Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 1bf2403

Browse files
author
Rodrigo Moya
authored
Merge pull request #9215 from mono/fix-1015867
Allow scaffolders to choose packages/versions by TFM
2 parents cc30628 + 81dc063 commit 1bf2403

File tree

7 files changed

+676
-8
lines changed

7 files changed

+676
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Microsoft.WebTools.Scaffolding.Core.Config
2+
{
3+
class PackageDescription
4+
{
5+
public string PackageId { get; set; }
6+
public string MinVersion { get; set; }
7+
public string MaxVersion { get; set; }
8+
public bool IsOptionalEfPackage { get; set; } = false;
9+
public bool IsOptionalIdentityPackage { get; set; } = false;
10+
}
11+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Threading.Tasks;
7+
using MonoDevelop.Core.Web;
8+
using Newtonsoft.Json;
9+
10+
namespace Microsoft.WebTools.Scaffolding.Core.Config
11+
{
12+
class ScaffoldingConfig
13+
{
14+
public static string ConfigPath { get; private set; } = Path.GetDirectoryName (typeof (ScaffoldingConfig).Assembly.Location);
15+
16+
public string Version { get; set; }
17+
18+
// LTS10, FTS11, NetStandard20, NetStandard21, and Net22 packages are set up as they are to maintain backwards compat.
19+
// They were (are) explicitly named sections before the config file format was generalized to support arbitrary support policy versions.
20+
public PackageDescription [] LTS10Packages { get; set; }
21+
22+
public PackageDescription [] FTS11Packages { get; set; }
23+
24+
public PackageDescription [] NetStandard20Packages { get; set; }
25+
26+
public PackageDescription [] NetStandard21Packages { get; set; }
27+
28+
public PackageDescription [] Net22Packages { get; set; }
29+
30+
// This is public so the Json deserialization works (and for testing).
31+
// The data should be accessed via TryGetPackagesForSupportPolicyVersion
32+
[JsonProperty]
33+
public Dictionary<string, PackageDescription []> DynamicVersionedPackages { get; set; }
34+
35+
public bool TryGetPackagesForSupportPolicyVersion (SupportPolicyVersion supportPolicyVersion, out PackageDescription [] packageDescriptions)
36+
{
37+
if (supportPolicyVersion == null || supportPolicyVersion.Version == null) {
38+
packageDescriptions = null;
39+
return false;
40+
}
41+
42+
if (supportPolicyVersion == SupportPolicyVersion.LTS10) {
43+
packageDescriptions = LTS10Packages;
44+
return true;
45+
}
46+
if (supportPolicyVersion == SupportPolicyVersion.FTS11) {
47+
packageDescriptions = FTS11Packages;
48+
return true;
49+
}
50+
if (supportPolicyVersion == SupportPolicyVersion.NetStandard20) {
51+
packageDescriptions = NetStandard20Packages;
52+
return true;
53+
}
54+
if (supportPolicyVersion == SupportPolicyVersion.NetStandard21) {
55+
packageDescriptions = NetStandard21Packages;
56+
return true;
57+
}
58+
if (supportPolicyVersion == SupportPolicyVersion.Net220) {
59+
packageDescriptions = Net22Packages;
60+
return true;
61+
}
62+
63+
if (DynamicVersionedPackages != null && DynamicVersionedPackages.TryGetValue (supportPolicyVersion.Version.ToString (), out packageDescriptions)) {
64+
return true;
65+
}
66+
67+
packageDescriptions = null;
68+
return false;
69+
}
70+
71+
static ScaffoldingConfig fetchedConfig;
72+
// This url will go live for 16.4
73+
static string packageVersionsUrl = "https://webpifeed.blob.core.windows.net/webpifeed/partners/scaffoldingpackageversions_2108718.json";
74+
75+
public static async Task<ScaffoldingConfig> LoadFromJsonAsync ()
76+
{
77+
if(fetchedConfig == null) {
78+
Stream stream;
79+
using var httpClient = HttpClientProvider.CreateHttpClient (packageVersionsUrl);
80+
httpClient.Timeout = TimeSpan.FromSeconds (2);
81+
82+
try {
83+
stream = await httpClient.GetStreamAsync (packageVersionsUrl);
84+
} catch {
85+
// fallback to embedded resource
86+
stream = typeof (ScaffoldingConfig).Assembly.GetManifestResourceStream ("ScaffoldingPackageVersions.json");
87+
}
88+
89+
var serializer = new JsonSerializer ();
90+
91+
using var sr = new StreamReader (stream);
92+
using var jsonTextReader = new JsonTextReader (sr);
93+
return serializer.Deserialize<ScaffoldingConfig> (jsonTextReader);
94+
}
95+
return fetchedConfig;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)