Ensure restore settings and package versions flow into test projects during CI builds

This commit is contained in:
Nate McMaster 2018-04-04 22:22:07 -07:00
Родитель 26957e090d
Коммит 9b5015d6fe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A778D9601BD78810
11 изменённых файлов: 51 добавлений и 74 удалений

2
.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

Просмотреть файл

@ -4,16 +4,16 @@
</PropertyGroup>
<PropertyGroup Label="Package Versions">
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15749</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30478</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
<MicrosoftExtensionsProcessSourcesPackageVersion>2.1.0-preview2-30478</MicrosoftExtensionsProcessSourcesPackageVersion>
<MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftAspNetCoreCertificatesGenerationSourcesPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30559</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
<MicrosoftExtensionsProcessSourcesPackageVersion>2.1.0-preview2-30559</MicrosoftExtensionsProcessSourcesPackageVersion>
<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>
<SystemDataSqlClientPackageVersion>4.5.0-preview3-26331-02</SystemDataSqlClientPackageVersion>
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview3-26331-02</SystemSecurityCryptographyCngPackageVersion>
<SystemDataSqlClientPackageVersion>4.5.0-preview2-26403-05</SystemDataSqlClientPackageVersion>
<SystemSecurityCryptographyCngPackageVersion>4.5.0-preview2-26403-05</SystemSecurityCryptographyCngPackageVersion>
<VisualStudio_NewtonsoftJsonPackageVersion>9.0.1</VisualStudio_NewtonsoftJsonPackageVersion>
<XunitPackageVersion>2.3.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>

Просмотреть файл

@ -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"), "<Project />");
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<AssemblyMetadataAttribute>()
.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);
}
}
}

Просмотреть файл

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>exe</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.5</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
</Project>

Просмотреть файл

@ -4,6 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>exe</OutputType>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -10,6 +10,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

Просмотреть файл

@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>exe</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>

Просмотреть файл

@ -21,31 +21,16 @@
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion)" />
</ItemGroup>
<Target Name="GenerateRestoreSourcesFile" BeforeTargets="Compile">
<PropertyGroup>
<RestoreSourcesFile>$(MSBuildThisFileDirectory)/TestProjects/NuGet.config</RestoreSourcesFile>
</PropertyGroup>
<CreateItem Include="$(RestoreSources)">
<Output TaskParameter="Include" ItemName="RestoreSourcesItems"/>
</CreateItem>
<ItemGroup>
<NuGetConfigLines Include="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;" />
<NuGetConfigLines Include="&lt;configuration&gt;" />
<NuGetConfigLines Include="&lt;packageSources&gt;" />
<NuGetConfigLines Include="&lt;clear/&gt;" />
<NuGetConfigLines Include="&lt;add key=&quot;%(RestoreSourcesItems.Identity)&quot; value=&quot;%(RestoreSourcesItems.Identity)&quot; /&gt;" />
<NuGetConfigLines Include="&lt;/packageSources&gt;" />
<NuGetConfigLines Include="&lt;/configuration&gt;" />
</ItemGroup>
<WriteLinesToFile
File="$(RestoreSourcesFile)"
Lines="@(NuGetConfigLines)"
Overwrite="true"
Encoding="UTF-8" />
</Target>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestSettings:RestoreSources</_Parameter1>
<_Parameter2>$(RestoreSources)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestSettings:RuntimeFrameworkVersion</_Parameter1>
<_Parameter2>$(RuntimeFrameworkVersion)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
<Target Name="CleanTestProjects" BeforeTargets="CoreCompile">
<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>