Merge pull request #815 from dotnet/pakrym/dllconfig
Add support for .config file generation for test projects
This commit is contained in:
commit
82013acbb2
8 changed files with 97 additions and 7 deletions
|
@ -89,8 +89,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
.GetDependencies()
|
||||
.SelectMany(e => e.RuntimeAssets())
|
||||
.CopyTo(outputPath);
|
||||
|
||||
GenerateBindingRedirects(context, exporter, outputPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -175,8 +173,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
return files;
|
||||
}
|
||||
|
||||
|
||||
private static void GenerateBindingRedirects(this ProjectContext context, LibraryExporter exporter, string outputPath)
|
||||
public static void GenerateBindingRedirects(this ProjectContext context, LibraryExporter exporter, string outputName)
|
||||
{
|
||||
var existingConfig = new DirectoryInfo(context.ProjectDirectory)
|
||||
.EnumerateFiles()
|
||||
|
@ -196,7 +193,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
|
||||
if (appConfig == null) { return; }
|
||||
|
||||
var path = Path.Combine(outputPath, context.ProjectFile.Name + ".exe.config");
|
||||
var path = outputName + ".config";
|
||||
using (var stream = File.Create(path))
|
||||
{
|
||||
appConfig.Save(stream);
|
||||
|
|
|
@ -332,8 +332,10 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath);
|
||||
}
|
||||
|
||||
bool generateBindingRedirects = false;
|
||||
if (success && !args.NoHostValue && compilationOptions.EmitEntryPoint.GetValueOrDefault())
|
||||
{
|
||||
generateBindingRedirects = true;
|
||||
var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers();
|
||||
var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids);
|
||||
runtimeContext
|
||||
|
@ -341,16 +343,22 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
}
|
||||
else if (!string.IsNullOrEmpty(context.ProjectFile.TestRunner))
|
||||
{
|
||||
generateBindingRedirects = true;
|
||||
var projectContext =
|
||||
ProjectContext.Create(context.ProjectDirectory, context.TargetFramework,
|
||||
new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()});
|
||||
|
||||
|
||||
projectContext
|
||||
.CreateExporter(args.ConfigValue)
|
||||
.GetDependencies(LibraryType.Package)
|
||||
.WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps));
|
||||
}
|
||||
|
||||
if (generateBindingRedirects)
|
||||
{
|
||||
context.GenerateBindingRedirects(exporter, outputName);
|
||||
}
|
||||
|
||||
return PrintSummary(diagnostics, sw, success);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,30 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
publishCommand.GetOutputDirectory().Should().HaveFile("System.Runtime.dll");
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void TestLibraryPublishTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
var testLibDir = root.CreateDirectory("TestLibraryWithRunner");
|
||||
|
||||
//copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithRunner"), testLibDir);
|
||||
|
||||
RunRestore(testLibDir.Path);
|
||||
|
||||
var testProject = GetProjectPath(testLibDir);
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.pdb");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.deps");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll.config");
|
||||
// dependencies should also be copied
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CompilationFailedTest()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public class WindowsOnlyFactAttribute : FactAttribute
|
||||
{
|
||||
public WindowsOnlyFactAttribute()
|
||||
{
|
||||
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows)
|
||||
{
|
||||
this.Skip = "This test requires windows to run";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,8 +12,11 @@
|
|||
"System.Runtime.InteropServices": "4.0.21-*",
|
||||
"System.Text.RegularExpressions": "4.0.11-*",
|
||||
"FluentAssertions": "4.0.0",
|
||||
"xunit": "2.1.0",
|
||||
|
||||
"Microsoft.DotNet.Cli.Utils": { "target": "project" },
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16530"
|
||||
|
||||
"Microsoft.DotNet.Cli.Utils": { "target": "project" }
|
||||
},
|
||||
|
||||
|
||||
|
|
8
test/TestProjects/TestLibraryWithRunner/NuGet.Config
Normal file
8
test/TestProjects/TestLibraryWithRunner/NuGet.Config
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||
<clear />
|
||||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>b76591d6-d105-441d-ab40-ac7e78eaf84d</ProjectGuid>
|
||||
<RootNamespace>TestLibraryWithRunner</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
12
test/TestProjects/TestLibraryWithRunner/project.json
Normal file
12
test/TestProjects/TestLibraryWithRunner/project.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"testRunner": "xunit",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final",
|
||||
"Newtonsoft.Json": "3.5.8"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue