Merge pull request #6234 from eerhardt/SelfContained
Add --self-contained to publish.
This commit is contained in:
commit
b00384f497
6 changed files with 104 additions and 21 deletions
|
@ -4,7 +4,7 @@
|
||||||
<CLI_SharedFrameworkVersion>2.0.0-preview1-001907-00</CLI_SharedFrameworkVersion>
|
<CLI_SharedFrameworkVersion>2.0.0-preview1-001907-00</CLI_SharedFrameworkVersion>
|
||||||
<CLI_MSBuild_Version>15.2.0-preview-000093-02</CLI_MSBuild_Version>
|
<CLI_MSBuild_Version>15.2.0-preview-000093-02</CLI_MSBuild_Version>
|
||||||
<CLI_Roslyn_Version>2.0.0-rc4-61325-08</CLI_Roslyn_Version>
|
<CLI_Roslyn_Version>2.0.0-rc4-61325-08</CLI_Roslyn_Version>
|
||||||
<CLI_NETSDK_Version>2.0.0-alpha-20170323-1</CLI_NETSDK_Version>
|
<CLI_NETSDK_Version>2.0.0-alpha-20170403-2</CLI_NETSDK_Version>
|
||||||
<CLI_NuGet_Version>4.3.0-beta1-2418</CLI_NuGet_Version>
|
<CLI_NuGet_Version>4.3.0-beta1-2418</CLI_NuGet_Version>
|
||||||
<CLI_WEBSDK_Version>1.0.0-rel-20170403-420</CLI_WEBSDK_Version>
|
<CLI_WEBSDK_Version>1.0.0-rel-20170403-420</CLI_WEBSDK_Version>
|
||||||
<CLI_TestPlatform_Version>15.1.0-preview-20170316-05</CLI_TestPlatform_Version>
|
<CLI_TestPlatform_Version>15.1.0-preview-20170316-05</CLI_TestPlatform_Version>
|
||||||
|
|
|
@ -20,5 +20,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
public const string FilterProjOption = "profile.xml";
|
public const string FilterProjOption = "profile.xml";
|
||||||
|
|
||||||
public const string FilterProjOptionDescription = "The XML file that contains the list of packages to be excluded from publish step.";
|
public const string FilterProjOptionDescription = "The XML file that contains the list of packages to be excluded from publish step.";
|
||||||
|
|
||||||
|
public const string SelfContainedOptionDescription = "Publish the .NET Core runtime with your application so the runtime doesn't need to be installed on the target machine. Defaults to 'true' if a runtime identifier is specified.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,26 @@ namespace Microsoft.DotNet.Cli
|
||||||
"-o|--output",
|
"-o|--output",
|
||||||
LocalizableStrings.OutputOptionDescription,
|
LocalizableStrings.OutputOptionDescription,
|
||||||
Accept.ExactlyOneArgument()
|
Accept.ExactlyOneArgument()
|
||||||
.With(name: LocalizableStrings.OutputOption)
|
.With(name: LocalizableStrings.OutputOption)
|
||||||
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
|
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
|
||||||
CommonOptions.ConfigurationOption(),
|
CommonOptions.ConfigurationOption(),
|
||||||
CommonOptions.VersionSuffixOption(),
|
CommonOptions.VersionSuffixOption(),
|
||||||
Create.Option(
|
Create.Option(
|
||||||
"--filter",
|
"--filter",
|
||||||
LocalizableStrings.FilterProjOptionDescription,
|
LocalizableStrings.FilterProjOptionDescription,
|
||||||
Accept.OneOrMoreArguments()
|
Accept.OneOrMoreArguments()
|
||||||
.With(name: LocalizableStrings.FilterProjOption)
|
.With(name: LocalizableStrings.FilterProjOption)
|
||||||
.ForwardAsSingle(o => $"/p:FilterProjectFiles={string.Join("%3B", o.Arguments)}")),
|
.ForwardAsSingle(o => $"/p:FilterProjectFiles={string.Join("%3B", o.Arguments)}")),
|
||||||
|
Create.Option(
|
||||||
|
"--self-contained",
|
||||||
|
LocalizableStrings.SelfContainedOptionDescription,
|
||||||
|
Accept.ZeroOrOneArgument()
|
||||||
|
.WithSuggestionsFrom("true", "false")
|
||||||
|
.ForwardAsSingle(o =>
|
||||||
|
{
|
||||||
|
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
|
||||||
|
return $"/p:SelfContained={value}";
|
||||||
|
})),
|
||||||
CommonOptions.VerbosityOption());
|
CommonOptions.VerbosityOption());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
private string _output;
|
private string _output;
|
||||||
private string _runtime;
|
private string _runtime;
|
||||||
private List<string> _profileFilterProject = new List<string>();
|
private List<string> _profileFilterProject = new List<string>();
|
||||||
|
private bool? _selfContained;
|
||||||
|
|
||||||
public PublishCommand WithFramework(string framework)
|
public PublishCommand WithFramework(string framework)
|
||||||
{
|
{
|
||||||
_framework = framework;
|
_framework = framework;
|
||||||
|
@ -37,12 +38,18 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishCommand WithProFileProject(string profileproj)
|
public PublishCommand WithProfileProject(string profileproj)
|
||||||
{
|
{
|
||||||
_profileFilterProject.Add( $" --filter {profileproj}");
|
_profileFilterProject.Add( $" --filter {profileproj}");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PublishCommand WithSelfContained(bool value)
|
||||||
|
{
|
||||||
|
_selfContained = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public override CommandResult Execute(string args = "")
|
public override CommandResult Execute(string args = "")
|
||||||
{
|
{
|
||||||
args = $"publish {BuildArgs()} {args}";
|
args = $"publish {BuildArgs()} {args}";
|
||||||
|
@ -61,7 +68,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
FrameworkOption,
|
FrameworkOption,
|
||||||
OutputOption,
|
OutputOption,
|
||||||
ProfileProjOption,
|
ProfileProjOption,
|
||||||
RuntimeOption);
|
RuntimeOption,
|
||||||
|
SelfContainedOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
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 RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
||||||
|
|
||||||
private string ProfileProjOption => string.Join(" ", _profileFilterProject);
|
private string ProfileProjOption => string.Join(" ", _profileFilterProject);
|
||||||
|
|
||||||
|
private string SelfContainedOption => _selfContained.HasValue ? $"--self-contained:{_selfContained.Value}" : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
.WithFramework(_tfm)
|
.WithFramework(_tfm)
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
.WithProFileProject(profileFilter)
|
.WithProfileProject(profileFilter)
|
||||||
.Execute()
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
.WithFramework(_tfm)
|
.WithFramework(_tfm)
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
.WithProFileProject(profileFilter)
|
.WithProfileProject(profileFilter)
|
||||||
.Execute()
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
.WithFramework(_tfm)
|
.WithFramework(_tfm)
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
.WithProFileProject(profileFilter)
|
.WithProfileProject(profileFilter)
|
||||||
.WithProFileProject(profileFilter1)
|
.WithProfileProject(profileFilter1)
|
||||||
.Execute()
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
|
|
||||||
new RestoreCommand()
|
new RestoreCommand()
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
.Execute("/p:SkipInvalidConfigurations=true")
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
new PublishCommand()
|
new PublishCommand()
|
||||||
|
@ -62,9 +62,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
.WithFramework("netcoreapp2.0")
|
.WithFramework("netcoreapp2.0")
|
||||||
.WithRuntime(rid)
|
.WithRuntime(rid)
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
//Workaround for https://github.com/dotnet/cli/issues/4501
|
.Execute()
|
||||||
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
|
|
||||||
.Execute("/p:SkipInvalidConfigurations=true")
|
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
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}")
|
.GetDirectory("bin", configuration, "netcoreapp2.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
|
||||||
.FullName;
|
.FullName;
|
||||||
|
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
EnsureProgramIsRunnable(outputProgram);
|
||||||
{
|
|
||||||
//Workaround for https://github.com/dotnet/corefx/issues/15516
|
|
||||||
Process.Start("chmod", $"u+x {outputProgram}").WaitForExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
new TestCommand(outputProgram)
|
new TestCommand(outputProgram)
|
||||||
.ExecuteWithCapturedOutput()
|
.ExecuteWithCapturedOutput()
|
||||||
|
@ -85,6 +79,73 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
||||||
.And.HaveStdOutContaining("Hello World");
|
.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]
|
[Fact]
|
||||||
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
|
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue