Merge branch 'release/2.1' into dev

This commit is contained in:
Nate McMaster 2018-04-04 23:55:09 -07:00
commit 344643581a
No known key found for this signature in database
GPG Key ID: A778D9601BD78810
10 changed files with 43 additions and 66 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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')" />

View File

@ -1,3 +0,0 @@
<Project>
<!-- Deliberately empty to prevent test apps from importing source props and targets. -->
</Project>

View File

@ -1,3 +0,0 @@
<Project>
<!-- Deliberately empty to prevent test apps from importing source props and targets. -->
</Project>