diff --git a/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj b/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj index 45b505c8d3..67493a7ea2 100644 --- a/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj +++ b/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj @@ -11,6 +11,7 @@ + diff --git a/AspNetCoreSdkTests/TemplateTests.cs b/AspNetCoreSdkTests/TemplateTests.cs index 93f0237b23..849cd5fc03 100644 --- a/AspNetCoreSdkTests/TemplateTests.cs +++ b/AspNetCoreSdkTests/TemplateTests.cs @@ -130,7 +130,7 @@ namespace AspNetCoreSdkTests NuGetPackageSource.NuGetOrg : NuGetPackageSource.None; // Pre-release SDKs require a private nuget feed - var onlinePackageSource = DotNetUtil.IsPreReleaseSdk ? + var onlinePackageSource = DotNetUtil.RequiresPrivateFeed ? NuGetPackageSource.EnvironmentVariableAndNuGetOrg : NuGetPackageSource.NuGetOrg; if (runtimeIdentifier == RuntimeIdentifier.None) diff --git a/AspNetCoreSdkTests/Util/DotNetUtil.cs b/AspNetCoreSdkTests/Util/DotNetUtil.cs index 689e10979f..182a2d9698 100644 --- a/AspNetCoreSdkTests/Util/DotNetUtil.cs +++ b/AspNetCoreSdkTests/Util/DotNetUtil.cs @@ -1,9 +1,12 @@ using Microsoft.Extensions.Internal; +using Newtonsoft.Json; using NuGet.Versioning; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Net.Http; using System.Text.RegularExpressions; using System.Threading; @@ -33,12 +36,14 @@ namespace AspNetCoreSdkTests.Util public static SemanticVersion RuntimeVersion => _versions.Value.RuntimeVersion; - public static bool IsPreReleaseSdk => - SdkVersion.IsPrerelease || - SdkVersion == new SemanticVersion(2, 1, 402); + private static readonly Lazy _requiresPrivateFeed = new Lazy(GetRequiresPrivateFeed, LazyThreadSafetyMode.PublicationOnly); + + public static bool RequiresPrivateFeed => _requiresPrivateFeed.Value; public static string TargetFrameworkMoniker => $"netcoreapp{RuntimeVersion.Major}.{RuntimeVersion.Minor}"; + private static readonly HttpClient _httpClient = new HttpClient(); + private static (SemanticVersion SdkVersion, SemanticVersion RuntimeVersion) GetVersions() { var info = RunDotNet("--info", workingDirectory: null); @@ -60,6 +65,16 @@ namespace AspNetCoreSdkTests.Util } } + // Private feed is required if nuget.org doesn't contain the matching version of Microsoft.NETCore.App + private static bool GetRequiresPrivateFeed() + { + var versionString = _httpClient.GetStringAsync("https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app/index.json").Result; + var definition = new { Versions = Enumerable.Empty() }; + + var versions = JsonConvert.DeserializeAnonymousType(versionString, definition); + return !versions.Versions.Contains(RuntimeVersion.ToString()); + } + private static IEnumerable> GetEnvironment(NuGetPackageSource nuGetPackageSource) { // Set NUGET_PACKAGES to an initially-empty, distinct folder for each NuGetPackageSource. This ensures packages are loaded