Update tests for SDK 2.1.301 (#10)
- Offline restore is broken in SDK 2.1.301 - "dotnet build" cannot use "--no-restore" if the app is self-contained and the SDK contains a patched runtime
This commit is contained in:
parent
a06a7b55c4
commit
43be2bff95
|
|
@ -1,4 +1,5 @@
|
||||||
using AspNetCoreSdkTests.Templates;
|
using AspNetCoreSdkTests.Templates;
|
||||||
|
using AspNetCoreSdkTests.Util;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -85,20 +86,25 @@ namespace AspNetCoreSdkTests
|
||||||
{
|
{
|
||||||
if (runtimeIdentifier == RuntimeIdentifier.None)
|
if (runtimeIdentifier == RuntimeIdentifier.None)
|
||||||
{
|
{
|
||||||
|
// Offline restore is broken in SDK 2.1.301 (https://github.com/aspnet/Universe/issues/1220)
|
||||||
|
var packageSource = (DotNetUtil.SdkVersion == new Version(2, 1, 301)) ? NuGetPackageSource.NuGetOrg : NuGetPackageSource.None;
|
||||||
|
|
||||||
// Framework-dependent
|
// Framework-dependent
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
Template.GetInstance<ClassLibraryTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<ClassLibraryTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
||||||
Template.GetInstance<ConsoleApplicationTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<ConsoleApplicationTemplate>(packageSource, runtimeIdentifier),
|
||||||
|
|
||||||
// Offline restore currently not supported for RazorClassLibrary template (https://github.com/aspnet/Universe/issues/1123)
|
// Offline restore currently not supported for RazorClassLibrary template (https://github.com/aspnet/Universe/issues/1123)
|
||||||
Template.GetInstance<RazorClassLibraryTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
Template.GetInstance<RazorClassLibraryTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<WebTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
|
||||||
Template.GetInstance<RazorTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<WebTemplate>(packageSource, runtimeIdentifier),
|
||||||
Template.GetInstance<MvcTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<RazorTemplate>(packageSource, runtimeIdentifier),
|
||||||
Template.GetInstance<AngularTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<MvcTemplate>(packageSource, runtimeIdentifier),
|
||||||
Template.GetInstance<ReactTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<AngularTemplate>(packageSource, runtimeIdentifier),
|
||||||
Template.GetInstance<ReactReduxTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<ReactTemplate>(packageSource, runtimeIdentifier),
|
||||||
Template.GetInstance<WebApiTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<ReactReduxTemplate>(packageSource, runtimeIdentifier),
|
||||||
|
Template.GetInstance<WebApiTemplate>(packageSource, runtimeIdentifier),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -108,15 +114,15 @@ namespace AspNetCoreSdkTests
|
||||||
{
|
{
|
||||||
// ClassLibrary does not require a package source, even for self-contained deployments
|
// ClassLibrary does not require a package source, even for self-contained deployments
|
||||||
Template.GetInstance<ClassLibraryTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
Template.GetInstance<ClassLibraryTemplate>(NuGetPackageSource.None, runtimeIdentifier),
|
||||||
Template.GetInstance<ConsoleApplicationTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<ConsoleApplicationTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<RazorClassLibraryTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
Template.GetInstance<RazorClassLibraryTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<WebTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<WebTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<RazorTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<RazorTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<MvcTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<MvcTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<AngularTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<AngularTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<ReactTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<ReactTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<ReactReduxTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<ReactReduxTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
Template.GetInstance<WebApiTemplate>(NuGetPackageSource.DotNetCore, runtimeIdentifier),
|
Template.GetInstance<WebApiTemplate>(NuGetPackageSource.NuGetOrg, runtimeIdentifier),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
// Build depends on Restore
|
// Build depends on Restore
|
||||||
_ = ObjFilesAfterRestore;
|
_ = ObjFilesAfterRestore;
|
||||||
|
|
||||||
DotNetUtil.Build(TempDir, RuntimeIdentifier);
|
DotNetUtil.Build(TempDir, NuGetPackageSource, RuntimeIdentifier);
|
||||||
return (IOUtil.GetFiles(Path.Combine(TempDir, "obj")), IOUtil.GetFiles(Path.Combine(TempDir, "bin")));
|
return (IOUtil.GetFiles(Path.Combine(TempDir, "obj")), IOUtil.GetFiles(Path.Combine(TempDir, "bin")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace AspNetCoreSdkTests.Util
|
namespace AspNetCoreSdkTests.Util
|
||||||
{
|
{
|
||||||
|
|
@ -22,6 +24,27 @@ namespace AspNetCoreSdkTests.Util
|
||||||
|
|
||||||
public static string PublishOutput => "pub";
|
public static string PublishOutput => "pub";
|
||||||
|
|
||||||
|
private static readonly Lazy<Version> _sdkVersion = new Lazy<Version>(GetSdkVersion, LazyThreadSafetyMode.PublicationOnly);
|
||||||
|
|
||||||
|
public static Version SdkVersion => _sdkVersion.Value;
|
||||||
|
|
||||||
|
private static Version GetSdkVersion()
|
||||||
|
{
|
||||||
|
var info = RunDotNet("--info", workingDirectory: null);
|
||||||
|
var versionString = Regex.Match(info, @"Version:\W*([0-9.]+)").Groups[1].Value;
|
||||||
|
var version = new Version(versionString);
|
||||||
|
|
||||||
|
// Supported version range is [2.1.300,2.1.301] (inclusive)
|
||||||
|
if (version >= new Version(2, 1, 300) && version <= new Version(2, 1, 301))
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unsupported SDK version: {version}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -45,9 +68,15 @@ namespace AspNetCoreSdkTests.Util
|
||||||
workingDirectory, GetEnvironment(packageSource));
|
workingDirectory, GetEnvironment(packageSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Build(string workingDirectory, RuntimeIdentifier runtimeIdentifier)
|
public static string Build(string workingDirectory, NuGetPackageSource packageSource, RuntimeIdentifier runtimeIdentifier)
|
||||||
{
|
{
|
||||||
return RunDotNet($"build --no-restore {runtimeIdentifier.RuntimeArgument}", workingDirectory);
|
// "dotnet build" cannot use "--no-restore" if the app is self-contained and the SDK contains a patched runtime
|
||||||
|
// https://github.com/dotnet/sdk/issues/2312, https://github.com/dotnet/cli/issues/9514
|
||||||
|
bool restoreRequired = (runtimeIdentifier != RuntimeIdentifier.None) && (DotNetUtil.SdkVersion >= new Version(2, 1, 301));
|
||||||
|
|
||||||
|
var restoreArgument = restoreRequired ? $"--no-cache {packageSource.SourceArgument}" : "--no-restore";
|
||||||
|
|
||||||
|
return RunDotNet($"build {restoreArgument} {runtimeIdentifier.RuntimeArgument}", workingDirectory, GetEnvironment(packageSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (Process Process, ConcurrentStringBuilder OutputBuilder, ConcurrentStringBuilder ErrorBuilder) Run(
|
public static (Process Process, ConcurrentStringBuilder OutputBuilder, ConcurrentStringBuilder ErrorBuilder) Run(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue