Merge pull request #6234 from eerhardt/SelfContained

Add --self-contained to publish.
This commit is contained in:
Eric Erhardt 2017-04-04 12:03:09 -05:00 committed by GitHub
commit b00384f497
6 changed files with 104 additions and 21 deletions

View file

@ -13,7 +13,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string _output;
private string _runtime;
private List<string> _profileFilterProject = new List<string>();
private bool? _selfContained;
public PublishCommand WithFramework(string framework)
{
_framework = framework;
@ -37,12 +38,18 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return this;
}
public PublishCommand WithProFileProject(string profileproj)
public PublishCommand WithProfileProject(string profileproj)
{
_profileFilterProject.Add( $" --filter {profileproj}");
return this;
}
public PublishCommand WithSelfContained(bool value)
{
_selfContained = value;
return this;
}
public override CommandResult Execute(string args = "")
{
args = $"publish {BuildArgs()} {args}";
@ -61,7 +68,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
FrameworkOption,
OutputOption,
ProfileProjOption,
RuntimeOption);
RuntimeOption,
SelfContainedOption);
}
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
@ -71,5 +79,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string ProfileProjOption => string.Join(" ", _profileFilterProject);
private string SelfContainedOption => _selfContained.HasValue ? $"--self-contained:{_selfContained.Value}" : "";
}
}

View file

@ -57,7 +57,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new PublishCommand()
.WithFramework(_tfm)
.WithWorkingDirectory(testProjectDirectory)
.WithProFileProject(profileFilter)
.WithProfileProject(profileFilter)
.Execute()
.Should().Pass();
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new PublishCommand()
.WithFramework(_tfm)
.WithWorkingDirectory(testProjectDirectory)
.WithProFileProject(profileFilter)
.WithProfileProject(profileFilter)
.Execute()
.Should().Pass();
@ -153,8 +153,8 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new PublishCommand()
.WithFramework(_tfm)
.WithWorkingDirectory(testProjectDirectory)
.WithProFileProject(profileFilter)
.WithProFileProject(profileFilter1)
.WithProfileProject(profileFilter)
.WithProfileProject(profileFilter1)
.Execute()
.Should().Pass();

View file

@ -27,7 +27,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("/p:SkipInvalidConfigurations=true")
.Execute()
.Should().Pass();
new PublishCommand()
@ -62,9 +62,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.WithFramework("netcoreapp2.0")
.WithRuntime(rid)
.WithWorkingDirectory(testProjectDirectory)
//Workaround for https://github.com/dotnet/cli/issues/4501
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
.Execute("/p:SkipInvalidConfigurations=true")
.Execute()
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
@ -73,11 +71,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.GetDirectory("bin", configuration, "netcoreapp2.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
.FullName;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//Workaround for https://github.com/dotnet/corefx/issues/15516
Process.Start("chmod", $"u+x {outputProgram}").WaitForExit();
}
EnsureProgramIsRunnable(outputProgram);
new TestCommand(outputProgram)
.ExecuteWithCapturedOutput()
@ -85,6 +79,73 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItPublishesARidSpecificAppSettingSelfContainedToTrue()
{
var testAppName = "MSBuildTestApp";
var outputDirectory = PublishAppWithSelfContained(testAppName, true);
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()
{
var testAppName = "MSBuildTestApp";
var outputDirectory = PublishAppWithSelfContained(testAppName, false);
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 PublishAppWithSelfContained(string testAppName, bool selfContained)
{
var testInstance = TestAssets.Get(testAppName)
.CreateInstance($"PublishesSelfContained{selfContained}")
.WithSourceFiles()
.WithRestoreFiles();
var testProjectDirectory = testInstance.Root;
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
new PublishCommand()
.WithRuntime(rid)
.WithSelfContained(selfContained)
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
return testProjectDirectory
.GetDirectory("bin", configuration, "netcoreapp2.0", 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();
}
}
[Fact]
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
{