From 9b5015d6fee90cc77c9130d3faf7904bcdd36ed6 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 4 Apr 2018 22:22:07 -0700 Subject: [PATCH] Ensure restore settings and package versions flow into test projects during CI builds --- .gitignore | 2 - build/dependencies.props | 16 +++--- .../Scenario/ProjectToolScenario.cs | 57 +++++++++---------- .../AppWithDeps/AppWithDeps.csproj | 1 + .../TestProjects/Dependency/Dependency.csproj | 5 +- .../GlobbingApp/GlobbingApp.csproj | 1 + .../KitchenSink/KitchenSink.csproj | 1 + .../TestProjects/NoDepsApp/NoDepsApp.csproj | 1 + .../dotnet-watch.FunctionalTests.csproj | 35 ++++-------- testWorkDir/Directory.Build.props | 3 - testWorkDir/Directory.Build.targets | 3 - 11 files changed, 51 insertions(+), 74 deletions(-) delete mode 100644 testWorkDir/Directory.Build.props delete mode 100644 testWorkDir/Directory.Build.targets diff --git a/.gitignore b/.gitignore index 78ed833761..01ed76be4f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,11 +29,9 @@ project.lock.json .build/ /.vs/ .vscode/ -testWorkDir/ *.nuget.props *.nuget.targets .idea/ .dotnet/ global.json *.binlog -test/dotnet-watch.FunctionalTests/TestProjects/NuGet.config \ No newline at end of file diff --git a/build/dependencies.props b/build/dependencies.props index 2c58c4330c..d79aa4648b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,16 +4,16 @@ 2.1.0-preview2-15749 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 - 2.1.0-preview2-30478 + 2.1.0-preview2-30559 + 2.1.0-preview2-30559 + 2.1.0-preview2-30559 + 2.1.0-preview2-30559 + 2.1.0-preview2-30559 2.0.0 - 2.1.0-preview3-26331-01 + 2.1.0-preview2-26403-06 15.6.1 - 4.5.0-preview3-26331-02 - 4.5.0-preview3-26331-02 + 4.5.0-preview2-26403-05 + 4.5.0-preview2-26403-05 9.0.1 2.3.1 2.4.0-beta.1.build3945 diff --git a/test/dotnet-watch.FunctionalTests/Scenario/ProjectToolScenario.cs b/test/dotnet-watch.FunctionalTests/Scenario/ProjectToolScenario.cs index a11310c6e9..a0a14093ec 100644 --- a/test/dotnet-watch.FunctionalTests/Scenario/ProjectToolScenario.cs +++ b/test/dotnet-watch.FunctionalTests/Scenario/ProjectToolScenario.cs @@ -5,9 +5,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using System.Xml.Linq; using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Tools.Internal; @@ -17,7 +19,6 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests { public class ProjectToolScenario : IDisposable { - private const string NugetConfigFileName = "NuGet.config"; private static readonly string TestProjectSourceRoot = Path.Combine(AppContext.BaseDirectory, "TestProjects"); private readonly ITestOutputHelper _logger; @@ -28,21 +29,18 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests public ProjectToolScenario(ITestOutputHelper logger) { + WorkFolder = Path.Combine(AppContext.BaseDirectory, "tmp", Path.GetRandomFileName()); + DotNetWatchPath = Path.Combine(AppContext.BaseDirectory, "tool", "dotnet-watch.dll"); + _logger = logger; - _logger?.WriteLine($"The temporary test folder is {TempFolder}"); - WorkFolder = Path.Combine(TempFolder, "work"); + _logger?.WriteLine($"The temporary test folder is {WorkFolder}"); CreateTestDirectory(); } - - public static string TestWorkFolder { get; } = Path.Combine(AppContext.BaseDirectory, "testWorkDir"); - - public string TempFolder { get; } = Path.Combine(TestWorkFolder, Guid.NewGuid().ToString("N")); - public string WorkFolder { get; } - public string DotNetWatchPath { get; } = Path.Combine(AppContext.BaseDirectory, "tool", "dotnet-watch.dll"); + public string DotNetWatchPath { get; } public void AddTestProjectFolder(string projectName) { @@ -149,42 +147,39 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests { Directory.CreateDirectory(WorkFolder); - var nugetConfigFilePath = FindNugetConfig(); + File.WriteAllText(Path.Combine(WorkFolder, "Directory.Build.props"), ""); - var tempNugetConfigFile = Path.Combine(WorkFolder, NugetConfigFileName); - File.Copy(nugetConfigFilePath, tempNugetConfigFile); + var restoreSources = GetMetadata("TestSettings:RestoreSources"); + var frameworkVersion = GetMetadata("TestSettings:RuntimeFrameworkVersion"); + + var dbTargets = new XDocument( + new XElement("Project", + new XElement("PropertyGroup", + new XElement("RuntimeFrameworkVersion", frameworkVersion), + new XElement("RestoreSources", restoreSources)))); + dbTargets.Save(Path.Combine(WorkFolder, "Directory.Build.targets")); } - private static string FindNugetConfig() + private string GetMetadata(string key) { - var currentDirPath = TestWorkFolder; - - string nugetConfigFile; - while (true) - { - nugetConfigFile = Path.Combine(currentDirPath, NugetConfigFileName); - if (File.Exists(nugetConfigFile)) - { - break; - } - - currentDirPath = Path.GetDirectoryName(currentDirPath); - } - - return nugetConfigFile; + return typeof(ProjectToolScenario) + .Assembly + .GetCustomAttributes() + .First(a => string.Equals(a.Key, key, StringComparison.Ordinal)) + .Value; } public void Dispose() { try { - Directory.Delete(TempFolder, recursive: true); + Directory.Delete(WorkFolder, recursive: true); } catch { - Console.WriteLine($"Failed to delete {TempFolder}. Retrying..."); + Console.WriteLine($"Failed to delete {WorkFolder}. Retrying..."); Thread.Sleep(TimeSpan.FromSeconds(5)); - Directory.Delete(TempFolder, recursive: true); + Directory.Delete(WorkFolder, recursive: true); } } } diff --git a/test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/AppWithDeps.csproj b/test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/AppWithDeps.csproj index 76d7446452..0dcb552112 100644 --- a/test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/AppWithDeps.csproj +++ b/test/dotnet-watch.FunctionalTests/TestProjects/AppWithDeps/AppWithDeps.csproj @@ -3,6 +3,7 @@ netcoreapp2.1 exe + true diff --git a/test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Dependency.csproj b/test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Dependency.csproj index 22361d48cb..0dbf97b944 100644 --- a/test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Dependency.csproj +++ b/test/dotnet-watch.FunctionalTests/TestProjects/Dependency/Dependency.csproj @@ -1,7 +1,8 @@ - netstandard1.5 + netstandard2.0 + true - \ No newline at end of file + diff --git a/test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/GlobbingApp.csproj b/test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/GlobbingApp.csproj index 60645a49da..a01efb4b2f 100644 --- a/test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/GlobbingApp.csproj +++ b/test/dotnet-watch.FunctionalTests/TestProjects/GlobbingApp/GlobbingApp.csproj @@ -4,6 +4,7 @@ netcoreapp2.1 exe false + true diff --git a/test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/KitchenSink.csproj b/test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/KitchenSink.csproj index 699071e138..72f7d5cae4 100644 --- a/test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/KitchenSink.csproj +++ b/test/dotnet-watch.FunctionalTests/TestProjects/KitchenSink/KitchenSink.csproj @@ -10,6 +10,7 @@ Exe netcoreapp2.1 + true diff --git a/test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/NoDepsApp.csproj b/test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/NoDepsApp.csproj index 86e88b8b95..b242bd2546 100644 --- a/test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/NoDepsApp.csproj +++ b/test/dotnet-watch.FunctionalTests/TestProjects/NoDepsApp/NoDepsApp.csproj @@ -3,6 +3,7 @@ netcoreapp2.1 exe + true diff --git a/test/dotnet-watch.FunctionalTests/dotnet-watch.FunctionalTests.csproj b/test/dotnet-watch.FunctionalTests/dotnet-watch.FunctionalTests.csproj index 5d97fcca6f..d7c0a3fdac 100644 --- a/test/dotnet-watch.FunctionalTests/dotnet-watch.FunctionalTests.csproj +++ b/test/dotnet-watch.FunctionalTests/dotnet-watch.FunctionalTests.csproj @@ -21,31 +21,16 @@ - - - $(MSBuildThisFileDirectory)/TestProjects/NuGet.config - - - - - - - - - - - - - - - - - - + + + <_Parameter1>TestSettings:RestoreSources + <_Parameter2>$(RestoreSources) + + + <_Parameter1>TestSettings:RuntimeFrameworkVersion + <_Parameter2>$(RuntimeFrameworkVersion) + + diff --git a/testWorkDir/Directory.Build.props b/testWorkDir/Directory.Build.props deleted file mode 100644 index b959507df8..0000000000 --- a/testWorkDir/Directory.Build.props +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/testWorkDir/Directory.Build.targets b/testWorkDir/Directory.Build.targets deleted file mode 100644 index b959507df8..0000000000 --- a/testWorkDir/Directory.Build.targets +++ /dev/null @@ -1,3 +0,0 @@ - - -