Ensure restore settings and package versions flow into test projects during CI builds
This commit is contained in:
parent
26957e090d
commit
9b5015d6fe
|
|
@ -29,11 +29,9 @@ project.lock.json
|
||||||
.build/
|
.build/
|
||||||
/.vs/
|
/.vs/
|
||||||
.vscode/
|
.vscode/
|
||||||
testWorkDir/
|
|
||||||
*.nuget.props
|
*.nuget.props
|
||||||
*.nuget.targets
|
*.nuget.targets
|
||||||
.idea/
|
.idea/
|
||||||
.dotnet/
|
.dotnet/
|
||||||
global.json
|
global.json
|
||||||
*.binlog
|
*.binlog
|
||||||
test/dotnet-watch.FunctionalTests/TestProjects/NuGet.config
|
|
||||||
|
|
@ -4,16 +4,16 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Package Versions">
|
<PropertyGroup Label="Package Versions">
|
||||||
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15749</InternalAspNetCoreSdkPackageVersion>
|
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15749</InternalAspNetCoreSdkPackageVersion>
|
||||||
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
|
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
|
||||||
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30478</MicrosoftAspNetCoreTestingPackageVersion>
|
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30559</MicrosoftAspNetCoreTestingPackageVersion>
|
||||||
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
|
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
|
||||||
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
|
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
|
||||||
<MicrosoftExtensionsProcessSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsProcessSourcesPackageVersion>
|
<MicrosoftExtensionsProcessSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsProcessSourcesPackageVersion>
|
||||||
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
|
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
|
||||||
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview3-26331-01</MicrosoftNETCoreApp21PackageVersion>
|
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26403-06</MicrosoftNETCoreApp21PackageVersion>
|
||||||
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
|
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
|
||||||
<SystemDataSqlClientPackageVersion>4.5.0-preview3-26331-02</SystemDataSqlClientPackageVersion>
|
<SystemDataSqlClientPackageVersion>4.5.0-preview2-26403-05</SystemDataSqlClientPackageVersion>
|
||||||
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview3-26331-02</SystemSecurityCryptographyCngPackageVersion>
|
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview2-26403-05</SystemSecurityCryptographyCngPackageVersion>
|
||||||
<VisualStudio_NewtonsoftJsonPackageVersion>9.0.1</VisualStudio_NewtonsoftJsonPackageVersion>
|
<VisualStudio_NewtonsoftJsonPackageVersion>9.0.1</VisualStudio_NewtonsoftJsonPackageVersion>
|
||||||
<XunitPackageVersion>2.3.1</XunitPackageVersion>
|
<XunitPackageVersion>2.3.1</XunitPackageVersion>
|
||||||
<XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>
|
<XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ 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.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Microsoft.Extensions.Tools.Internal;
|
using Microsoft.Extensions.Tools.Internal;
|
||||||
|
|
@ -17,7 +19,6 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
{
|
{
|
||||||
public class ProjectToolScenario : IDisposable
|
public class ProjectToolScenario : IDisposable
|
||||||
{
|
{
|
||||||
private const string NugetConfigFileName = "NuGet.config";
|
|
||||||
private static readonly string TestProjectSourceRoot = Path.Combine(AppContext.BaseDirectory, "TestProjects");
|
private static readonly string TestProjectSourceRoot = Path.Combine(AppContext.BaseDirectory, "TestProjects");
|
||||||
private readonly ITestOutputHelper _logger;
|
private readonly ITestOutputHelper _logger;
|
||||||
|
|
||||||
|
|
@ -28,21 +29,18 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
|
|
||||||
public ProjectToolScenario(ITestOutputHelper logger)
|
public ProjectToolScenario(ITestOutputHelper logger)
|
||||||
{
|
{
|
||||||
|
WorkFolder = Path.Combine(AppContext.BaseDirectory, "tmp", Path.GetRandomFileName());
|
||||||
|
DotNetWatchPath = Path.Combine(AppContext.BaseDirectory, "tool", "dotnet-watch.dll");
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logger?.WriteLine($"The temporary test folder is {TempFolder}");
|
_logger?.WriteLine($"The temporary test folder is {WorkFolder}");
|
||||||
WorkFolder = Path.Combine(TempFolder, "work");
|
|
||||||
|
|
||||||
CreateTestDirectory();
|
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 WorkFolder { get; }
|
||||||
|
|
||||||
public string DotNetWatchPath { get; } = Path.Combine(AppContext.BaseDirectory, "tool", "dotnet-watch.dll");
|
public string DotNetWatchPath { get; }
|
||||||
|
|
||||||
public void AddTestProjectFolder(string projectName)
|
public void AddTestProjectFolder(string projectName)
|
||||||
{
|
{
|
||||||
|
|
@ -149,42 +147,39 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(WorkFolder);
|
Directory.CreateDirectory(WorkFolder);
|
||||||
|
|
||||||
var nugetConfigFilePath = FindNugetConfig();
|
File.WriteAllText(Path.Combine(WorkFolder, "Directory.Build.props"), "<Project />");
|
||||||
|
|
||||||
var tempNugetConfigFile = Path.Combine(WorkFolder, NugetConfigFileName);
|
var restoreSources = GetMetadata("TestSettings:RestoreSources");
|
||||||
File.Copy(nugetConfigFilePath, tempNugetConfigFile);
|
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;
|
return typeof(ProjectToolScenario)
|
||||||
|
.Assembly
|
||||||
string nugetConfigFile;
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
while (true)
|
.First(a => string.Equals(a.Key, key, StringComparison.Ordinal))
|
||||||
{
|
.Value;
|
||||||
nugetConfigFile = Path.Combine(currentDirPath, NugetConfigFileName);
|
|
||||||
if (File.Exists(nugetConfigFile))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentDirPath = Path.GetDirectoryName(currentDirPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nugetConfigFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.Delete(TempFolder, recursive: true);
|
Directory.Delete(WorkFolder, recursive: true);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failed to delete {TempFolder}. Retrying...");
|
Console.WriteLine($"Failed to delete {WorkFolder}. Retrying...");
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(5));
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||||
Directory.Delete(TempFolder, recursive: true);
|
Directory.Delete(WorkFolder, recursive: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<OutputType>exe</OutputType>
|
<OutputType>exe</OutputType>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard1.5</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<OutputType>exe</OutputType>
|
<OutputType>exe</OutputType>
|
||||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<OutputType>exe</OutputType>
|
<OutputType>exe</OutputType>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -21,31 +21,16 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="GenerateRestoreSourcesFile" BeforeTargets="Compile">
|
<ItemGroup>
|
||||||
<PropertyGroup>
|
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||||
<RestoreSourcesFile>$(MSBuildThisFileDirectory)/TestProjects/NuGet.config</RestoreSourcesFile>
|
<_Parameter1>TestSettings:RestoreSources</_Parameter1>
|
||||||
</PropertyGroup>
|
<_Parameter2>$(RestoreSources)</_Parameter2>
|
||||||
|
</AssemblyAttribute>
|
||||||
<CreateItem Include="$(RestoreSources)">
|
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||||
<Output TaskParameter="Include" ItemName="RestoreSourcesItems"/>
|
<_Parameter1>TestSettings:RuntimeFrameworkVersion</_Parameter1>
|
||||||
</CreateItem>
|
<_Parameter2>$(RuntimeFrameworkVersion)</_Parameter2>
|
||||||
|
</AssemblyAttribute>
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<NuGetConfigLines Include="<?xml version="1.0" encoding="utf-8"?>" />
|
|
||||||
<NuGetConfigLines Include="<configuration>" />
|
|
||||||
<NuGetConfigLines Include="<packageSources>" />
|
|
||||||
<NuGetConfigLines Include="<clear/>" />
|
|
||||||
<NuGetConfigLines Include="<add key="%(RestoreSourcesItems.Identity)" value="%(RestoreSourcesItems.Identity)" />" />
|
|
||||||
<NuGetConfigLines Include="</packageSources>" />
|
|
||||||
<NuGetConfigLines Include="</configuration>" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<WriteLinesToFile
|
|
||||||
File="$(RestoreSourcesFile)"
|
|
||||||
Lines="@(NuGetConfigLines)"
|
|
||||||
Overwrite="true"
|
|
||||||
Encoding="UTF-8" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<Target Name="CleanTestProjects" BeforeTargets="CoreCompile">
|
<Target Name="CleanTestProjects" BeforeTargets="CoreCompile">
|
||||||
<RemoveDir Directories="$(TargetDir)TestProjects" Condition="Exists('$(TargetDir)TestProjects')" />
|
<RemoveDir Directories="$(TargetDir)TestProjects" Condition="Exists('$(TargetDir)TestProjects')" />
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
<Project>
|
|
||||||
<!-- Deliberately empty to prevent test apps from importing source props and targets. -->
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
<Project>
|
|
||||||
<!-- Deliberately empty to prevent test apps from importing source props and targets. -->
|
|
||||||
</Project>
|
|
||||||
Loading…
Reference in New Issue