Merge pull request #9460 from peterhuene/fx-dep-apphost

Implement `mode` option for `dotnet publish`.
This commit is contained in:
William Li 2018-06-15 09:40:19 -07:00 committed by GitHub
commit f66dc4e08b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 604 additions and 200 deletions

View file

@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string _output;
private string _runtime;
private List<string> _targetManifests = new List<string>();
private bool? _selfContained;
private string _mode;
public PublishCommand WithFramework(string framework)
{
@ -44,9 +44,9 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return this;
}
public PublishCommand WithSelfContained(bool value)
public PublishCommand WithMode(string value)
{
_selfContained = value;
_mode = value;
return this;
}
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
OutputOption,
TargetOption,
RuntimeOption,
SelfContainedOption);
ModeOption);
}
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
@ -80,6 +80,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string TargetOption => string.Join(" ", _targetManifests);
private string SelfContainedOption => _selfContained.HasValue ? $"--self-contained:{_selfContained.Value}" : "";
private string ModeOption => string.IsNullOrEmpty(_mode) ? "" : $"--mode {_mode}";
}
}

View file

@ -11,6 +11,7 @@ using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
namespace Microsoft.DotNet.Cli.Publish.Tests
{
@ -95,62 +96,61 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.And.HaveStdOutContaining("project.assets.json");
}
[Fact]
public void ItPublishesARunnableSelfContainedApp()
[Theory]
[InlineData("self-contained", null)]
[InlineData(null, null)]
[InlineData(null, "--self-contained")]
[InlineData(null, "--self-contained=true")]
public void ItPublishesSelfContainedWithRid(string mode, string args)
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles()
.WithRestoreFiles();
var testProjectDirectory = testInstance.Root;
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
new PublishCommand()
.WithFramework("netcoreapp2.1")
.WithRuntime(rid)
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
var outputProgram = testProjectDirectory
.GetDirectory("bin", configuration, "netcoreapp2.1", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
.FullName;
EnsureProgramIsRunnable(outputProgram);
new TestCommand(outputProgram)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItPublishesARidSpecificAppSettingSelfContainedToTrue()
{
var testAppName = "MSBuildTestApp";
var outputDirectory = PublishAppWithSelfContained(testAppName, true);
var outputDirectory = PublishApp(testAppName, rid, mode, args);
var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}");
EnsureProgramIsRunnable(outputProgram);
new TestCommand(outputProgram)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItPublishesARidSpecificAppSettingSelfContainedToFalse()
[Theory]
[InlineData("fx-dependent", null)]
[InlineData(null, "--self-contained=false")]
public void ItPublishesFrameworkDependentWithRid(string mode, string args)
{
var testAppName = "MSBuildTestApp";
var outputDirectory = PublishAppWithSelfContained(testAppName, false);
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
var outputDirectory = PublishApp(testAppName, rid, mode, args);
outputDirectory.Should().OnlyHaveFiles(new[] {
$"{testAppName}{Constants.ExeSuffix}",
$"{testAppName}.dll",
$"{testAppName}.pdb",
$"{testAppName}.deps.json",
$"{testAppName}.runtimeconfig.json",
});
var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}");
var command = new TestCommand(outputProgram);
command.Environment[Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)"] =
new RepoDirectoriesProvider().DotnetRoot;
command.ExecuteWithCapturedOutput()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItPublishesFrameworkDependentNoExeWithRid()
{
var testAppName = "MSBuildTestApp";
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
var outputDirectory = PublishApp(testAppName, rid, mode: "fx-dependent-no-exe");
outputDirectory.Should().OnlyHaveFiles(new[] {
$"{testAppName}.dll",
@ -165,36 +165,48 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.And.HaveStdOutContaining("Hello World");
}
private DirectoryInfo PublishAppWithSelfContained(string testAppName, bool selfContained)
[Theory]
[InlineData("fx-dependent-no-exe", null)]
[InlineData("fx-dependent", null)]
[InlineData(null, "--self-contained=false")]
[InlineData(null, null)]
public void ItPublishesFrameworkDependentWithoutRid(string mode, string args)
{
var testAppName = "MSBuildTestApp";
var outputDirectory = PublishApp(testAppName, rid: null, mode: mode, args: args);
outputDirectory.Should().OnlyHaveFiles(new[] {
$"{testAppName}.dll",
$"{testAppName}.pdb",
$"{testAppName}.deps.json",
$"{testAppName}.runtimeconfig.json",
});
new DotnetCommand()
.ExecuteWithCapturedOutput(Path.Combine(outputDirectory.FullName, $"{testAppName}.dll"))
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
private DirectoryInfo PublishApp(string testAppName, string rid, string mode, string args = null)
{
var testInstance = TestAssets.Get(testAppName)
.CreateInstance($"PublishesSelfContained{selfContained}")
.CreateInstance($"PublishApp_{rid ?? "none"}_{mode ?? "none"}_{args ?? "none"}")
.WithSourceFiles()
.WithRestoreFiles();
var testProjectDirectory = testInstance.Root;
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
new PublishCommand()
.WithRuntime(rid)
.WithSelfContained(selfContained)
.WithMode(mode)
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Execute(args ?? "")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
return testProjectDirectory
.GetDirectory("bin", configuration, "netcoreapp2.1", rid, "publish");
}
private static void EnsureProgramIsRunnable(string path)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//Workaround for https://github.com/dotnet/corefx/issues/15516
Process.Start("chmod", $"u+x {path}").WaitForExit();
}
.GetDirectory("bin", configuration, "netcoreapp2.1", rid ?? "", "publish");
}
[Fact]
@ -324,5 +336,24 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.Should()
.Fail();
}
[Fact]
public void ItFailsToPublishIfBothModeAndSelfContainedAreSpecified()
{
var testInstance = TestAssets.Get("MSBuildTestApp")
.CreateInstance()
.WithSourceFiles()
.WithRestoreFiles();
var testProjectDirectory = testInstance.Root;
new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("--self-contained --mode fx-dependent")
.Should()
.Fail()
.And
.HaveStdErrContaining(LocalizableStrings.PublishModeAndSelfContainedOptionsConflict);
}
}
}

View file

@ -4,6 +4,9 @@
<RuntimeFrameworkVersion>$(MicrosoftNETCoreAppPackageVersion)</RuntimeFrameworkVersion>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dotnet-publish.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.4;portable-net451+win8</AssetTargetFallback>
</PropertyGroup>
@ -16,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Tools.Tests.Utilities\Microsoft.DotNet.Tools.Tests.Utilities.csproj" />
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
</ItemGroup>
<ItemGroup>