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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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>