diff --git a/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj b/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj
index 3028413b33..1989546e1a 100644
--- a/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj
+++ b/AspNetCoreSdkTests/AspNetCoreSdkTests.csproj
@@ -15,16 +15,4 @@
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
-
diff --git a/AspNetCoreSdkTests/TemplateTests.cs b/AspNetCoreSdkTests/FrameworkDependent.cs
similarity index 76%
rename from AspNetCoreSdkTests/TemplateTests.cs
rename to AspNetCoreSdkTests/FrameworkDependent.cs
index 80804a4f72..eb865fa816 100644
--- a/AspNetCoreSdkTests/TemplateTests.cs
+++ b/AspNetCoreSdkTests/FrameworkDependent.cs
@@ -7,7 +7,7 @@ using System.Net;
namespace AspNetCoreSdkTests
{
[TestFixture]
- public class TemplateTests
+ public class FrameworkDependent
{
[Test]
[TestCaseSource(nameof(RestoreData))]
@@ -48,19 +48,19 @@ namespace AspNetCoreSdkTests
public static IEnumerable RestoreData = new[]
{
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
// Offline restore currently not supported for RazorClassLibrary template (https://github.com/aspnet/Universe/issues/1123)
- Template.GetInstance(NuGetConfig.NuGetOrg),
+ Template.GetInstance(NuGetPackageSource.NuGetOrg),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
- Template.GetInstance(NuGetConfig.Empty),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
+ Template.GetInstance(NuGetPackageSource.None),
};
public static IEnumerable BuildData => RestoreData;
diff --git a/AspNetCoreSdkTests/NuGetConfig.cs b/AspNetCoreSdkTests/NuGetConfig.cs
deleted file mode 100644
index 8443084754..0000000000
--- a/AspNetCoreSdkTests/NuGetConfig.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace AspNetCoreSdkTests
-{
- public enum NuGetConfig
- {
- Empty,
- DotNetCore,
- NuGetOrg
- }
-}
diff --git a/AspNetCoreSdkTests/NuGetConfig/NuGet.DotNetCore.config b/AspNetCoreSdkTests/NuGetConfig/NuGet.DotNetCore.config
deleted file mode 100644
index fc7c007517..0000000000
--- a/AspNetCoreSdkTests/NuGetConfig/NuGet.DotNetCore.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/AspNetCoreSdkTests/NuGetConfig/NuGet.Empty.config b/AspNetCoreSdkTests/NuGetConfig/NuGet.Empty.config
deleted file mode 100644
index 4bb3170917..0000000000
--- a/AspNetCoreSdkTests/NuGetConfig/NuGet.Empty.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/AspNetCoreSdkTests/NuGetConfig/NuGet.NuGetOrg.config b/AspNetCoreSdkTests/NuGetConfig/NuGet.NuGetOrg.config
deleted file mode 100644
index b0743e46f8..0000000000
--- a/AspNetCoreSdkTests/NuGetConfig/NuGet.NuGetOrg.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/AspNetCoreSdkTests/NuGetPackageSource.cs b/AspNetCoreSdkTests/NuGetPackageSource.cs
new file mode 100644
index 0000000000..206102f222
--- /dev/null
+++ b/AspNetCoreSdkTests/NuGetPackageSource.cs
@@ -0,0 +1,9 @@
+namespace AspNetCoreSdkTests
+{
+ public enum NuGetPackageSource
+ {
+ None,
+ NuGetOrg,
+ EnvironmentVariable,
+ }
+}
diff --git a/AspNetCoreSdkTests/Templates/Template.cs b/AspNetCoreSdkTests/Templates/Template.cs
index 0910768e80..d1d267656d 100644
--- a/AspNetCoreSdkTests/Templates/Template.cs
+++ b/AspNetCoreSdkTests/Templates/Template.cs
@@ -21,11 +21,11 @@ namespace AspNetCoreSdkTests.Templates
ServerCertificateCustomValidationCallback = (m, c, ch, p) => true
});
- private static ConcurrentDictionary<(Type, NuGetConfig), Template> _templates = new ConcurrentDictionary<(Type, NuGetConfig), Template>();
+ private static ConcurrentDictionary<(Type, NuGetPackageSource), Template> _templates = new ConcurrentDictionary<(Type, NuGetPackageSource), Template>();
- public static T GetInstance(NuGetConfig nuGetConfig) where T : Template, new()
+ public static T GetInstance(NuGetPackageSource nuGetPackageSource) where T : Template, new()
{
- return (T)_templates.GetOrAdd((typeof(T), nuGetConfig), (k) => new T() { NuGetConfig = nuGetConfig });
+ return (T)_templates.GetOrAdd((typeof(T), nuGetPackageSource), (k) => new T() { NuGetPackageSource = nuGetPackageSource });
}
private Lazy> _objFilesAfterRestore;
@@ -34,7 +34,7 @@ namespace AspNetCoreSdkTests.Templates
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterRun;
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterExec;
- public NuGetConfig NuGetConfig { get; private set; }
+ public NuGetPackageSource NuGetPackageSource { get; private set; }
protected Template()
{
@@ -54,9 +54,9 @@ namespace AspNetCoreSdkTests.Templates
GetHttpResponsesAfterExec, LazyThreadSafetyMode.ExecutionAndPublication);
}
- public override string ToString() => $"{Name},{NuGetConfig}";
+ public override string ToString() => $"{Name},{NuGetPackageSource}";
- private string TempDir => Path.Combine(AssemblySetUp.TempDir, Name, NuGetConfig.ToString());
+ private string TempDir => Path.Combine(AssemblySetUp.TempDir, Name, NuGetPackageSource.ToString());
public abstract string Name { get; }
public abstract TemplateType Type { get; }
@@ -89,8 +89,8 @@ namespace AspNetCoreSdkTests.Templates
{
Directory.CreateDirectory(TempDir);
DotNetUtil.New(Name, TempDir);
- DotNetUtil.Restore(TempDir, NuGetConfig);
- return IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "obj"));
+ DotNetUtil.Restore(TempDir, NuGetPackageSource);
+ return IOUtil.GetFiles(Path.Combine(TempDir, "obj"));
}
private (IEnumerable ObjFiles, IEnumerable BinFiles) GetFilesAfterBuild()
@@ -99,7 +99,7 @@ namespace AspNetCoreSdkTests.Templates
_ = ObjFilesAfterRestore;
DotNetUtil.Build(TempDir);
- return (IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "obj")), IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "bin")));
+ return (IOUtil.GetFiles(Path.Combine(TempDir, "obj")), IOUtil.GetFiles(Path.Combine(TempDir, "bin")));
}
private IEnumerable GetFilesAfterPublish()
@@ -108,7 +108,7 @@ namespace AspNetCoreSdkTests.Templates
_ = BinFilesAfterBuild;
DotNetUtil.Publish(TempDir);
- return IOUtil.GetFiles(System.IO.Path.Combine(TempDir, DotNetUtil.PublishOutput));
+ return IOUtil.GetFiles(Path.Combine(TempDir, DotNetUtil.PublishOutput));
}
private (HttpResponseMessage Http, HttpResponseMessage Https) GetHttpResponsesAfterRun()
diff --git a/AspNetCoreSdkTests/Util/DotNetUtil.cs b/AspNetCoreSdkTests/Util/DotNetUtil.cs
index 22fbd999cb..cf8c7a6c41 100644
--- a/AspNetCoreSdkTests/Util/DotNetUtil.cs
+++ b/AspNetCoreSdkTests/Util/DotNetUtil.cs
@@ -8,6 +8,15 @@ namespace AspNetCoreSdkTests.Util
{
internal static class DotNetUtil
{
+ private const string _clearPackageSourcesNuGetConfig =
+@"
+
+
+
+
+
+";
+
// Bind to dynamic port 0 to avoid port conflicts during parallel tests
private const string _urls = "--urls http://127.0.0.1:0;https://127.0.0.1:0";
@@ -22,13 +31,16 @@ namespace AspNetCoreSdkTests.Util
public static string New(string template, string workingDirectory)
{
+ // Clear all packages sources by default. May be overridden by NuGetPackageSource parameter.
+ File.WriteAllText(Path.Combine(workingDirectory, "NuGet.config"), _clearPackageSourcesNuGetConfig);
+
return RunDotNet($"new {template} --name {template} --output . --no-restore", workingDirectory, GetEnvironment(workingDirectory));
}
- public static string Restore(string workingDirectory, NuGetConfig config)
+ public static string Restore(string workingDirectory, NuGetPackageSource packageSource)
{
- var configPath = Path.GetFullPath(Path.Combine("NuGetConfig", $"NuGet.{config}.config"));
- return RunDotNet($"restore --no-cache --configfile {configPath}", workingDirectory, GetEnvironment(workingDirectory));
+ var sourceArgument = GetSourceArgument(packageSource);
+ return RunDotNet($"restore --no-cache{sourceArgument}", workingDirectory, GetEnvironment(workingDirectory));
}
public static string Build(string workingDirectory)
@@ -52,6 +64,24 @@ namespace AspNetCoreSdkTests.Util
return RunDotNet($"publish --no-build -o {PublishOutput}", workingDirectory, GetEnvironment(workingDirectory));
}
+ private static string GetSourceArgument(NuGetPackageSource packageSource)
+ {
+ switch (packageSource)
+ {
+ case NuGetPackageSource.None:
+ return string.Empty;
+ case NuGetPackageSource.NuGetOrg:
+ return " --source https://api.nuget.org/v3/index.json";
+ case NuGetPackageSource.EnvironmentVariable:
+ var env = Environment.GetEnvironmentVariable("NUGET_PACKAGE_SOURCE");
+ return string.IsNullOrEmpty(env) ?
+ throw new InvalidOperationException("Environment variable NUGET_PACKAGE_SOURCE is required but not set") :
+ $" --source env";
+ default:
+ throw new ArgumentException("Invalid value", nameof(packageSource));
+ }
+ }
+
private static string RunDotNet(string arguments, string workingDirectory,
IEnumerable> environment = null, bool throwOnError = true)
{