Automatically detect if private feed is required (#16)
This commit is contained in:
parent
3442e95bee
commit
ba2eacc3f5
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
<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="NuGet.Versioning" Version="4.7.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ namespace AspNetCoreSdkTests
|
||||||
NuGetPackageSource.NuGetOrg : NuGetPackageSource.None;
|
NuGetPackageSource.NuGetOrg : NuGetPackageSource.None;
|
||||||
|
|
||||||
// Pre-release SDKs require a private nuget feed
|
// Pre-release SDKs require a private nuget feed
|
||||||
var onlinePackageSource = DotNetUtil.IsPreReleaseSdk ?
|
var onlinePackageSource = DotNetUtil.RequiresPrivateFeed ?
|
||||||
NuGetPackageSource.EnvironmentVariableAndNuGetOrg : NuGetPackageSource.NuGetOrg;
|
NuGetPackageSource.EnvironmentVariableAndNuGetOrg : NuGetPackageSource.NuGetOrg;
|
||||||
|
|
||||||
if (runtimeIdentifier == RuntimeIdentifier.None)
|
if (runtimeIdentifier == RuntimeIdentifier.None)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
|
@ -33,12 +36,14 @@ namespace AspNetCoreSdkTests.Util
|
||||||
|
|
||||||
public static SemanticVersion RuntimeVersion => _versions.Value.RuntimeVersion;
|
public static SemanticVersion RuntimeVersion => _versions.Value.RuntimeVersion;
|
||||||
|
|
||||||
public static bool IsPreReleaseSdk =>
|
private static readonly Lazy<bool> _requiresPrivateFeed = new Lazy<bool>(GetRequiresPrivateFeed, LazyThreadSafetyMode.PublicationOnly);
|
||||||
SdkVersion.IsPrerelease ||
|
|
||||||
SdkVersion == new SemanticVersion(2, 1, 402);
|
public static bool RequiresPrivateFeed => _requiresPrivateFeed.Value;
|
||||||
|
|
||||||
public static string TargetFrameworkMoniker => $"netcoreapp{RuntimeVersion.Major}.{RuntimeVersion.Minor}";
|
public static string TargetFrameworkMoniker => $"netcoreapp{RuntimeVersion.Major}.{RuntimeVersion.Minor}";
|
||||||
|
|
||||||
|
private static readonly HttpClient _httpClient = new HttpClient();
|
||||||
|
|
||||||
private static (SemanticVersion SdkVersion, SemanticVersion RuntimeVersion) GetVersions()
|
private static (SemanticVersion SdkVersion, SemanticVersion RuntimeVersion) GetVersions()
|
||||||
{
|
{
|
||||||
var info = RunDotNet("--info", workingDirectory: null);
|
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)
|
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
|
// Set NUGET_PACKAGES to an initially-empty, distinct folder for each NuGetPackageSource. This ensures packages are loaded
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue