Automatically detect if private feed is required (#16)
This commit is contained in:
parent
3442e95bee
commit
ba2eacc3f5
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="NuGet.Versioning" Version="4.7.0" />
|
||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<bool> _requiresPrivateFeed = new Lazy<bool>(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<string>() };
|
||||
|
||||
var versions = JsonConvert.DeserializeAnonymousType(versionString, definition);
|
||||
return !versions.Versions.Contains(RuntimeVersion.ToString());
|
||||
}
|
||||
|
||||
private static IEnumerable<KeyValuePair<string, string>> GetEnvironment(NuGetPackageSource nuGetPackageSource)
|
||||
{
|
||||
// Set NUGET_PACKAGES to an initially-empty, distinct folder for each NuGetPackageSource. This ensures packages are loaded
|
||||
|
|
|
|||
Loading…
Reference in New Issue