Add dotnet publish3 command.

This commit is contained in:
Eric Erhardt 2016-09-23 11:11:44 -05:00
parent d4f6144355
commit eed29be806
8 changed files with 213 additions and 1 deletions

View file

@ -170,6 +170,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-vstest.Tests", "test
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-msbuild.Tests", "test\dotnet-msbuild.Tests\dotnet-msbuild.Tests.xproj", "{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-publish3.Tests", "test\dotnet-publish3.Tests\dotnet-publish3.Tests.xproj", "{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -982,6 +984,22 @@ Global
{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Debug|x64.ActiveCfg = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Debug|x64.Build.0 = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Release|Any CPU.Build.0 = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Release|x64.ActiveCfg = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.Release|x64.Build.0 = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1045,5 +1063,6 @@ Global
{6D028154-5518-4A56-BAD6-938A90E5BCF6} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{9F5AE280-A040-4160-9799-6504D907742D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{2FFCBDF0-BA36-4393-8DDB-1AE04AEA3CD6} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection
EndGlobal

View file

@ -21,6 +21,7 @@ using Microsoft.DotNet.Tools.New;
using Microsoft.DotNet.Tools.NuGet;
using Microsoft.DotNet.Tools.Pack3;
using Microsoft.DotNet.Tools.Publish;
using Microsoft.DotNet.Tools.Publish3;
using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Tools.Restore3;
using Microsoft.DotNet.Tools.Run;
@ -48,6 +49,7 @@ namespace Microsoft.DotNet.Cli
["msbuild"] = MSBuildCommand.Run,
["run3"] = Run3Command.Run,
["restore3"] = Restore3Command.Run,
["publish3"] = Publish3Command.Run,
["vstest"] = VSTestCommand.Run,
["pack3"] = Pack3Command.Run,
["migrate"] = MigrateCommand.Run,

View file

@ -0,0 +1,78 @@
// 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 System.Collections.Generic;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.MSBuild;
namespace Microsoft.DotNet.Tools.Publish3
{
public class Publish3Command
{
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "dotnet publish3";
app.FullName = ".NET Publisher";
app.Description = "Publisher for the .NET Platform";
app.AllowArgumentSeparator = true;
app.HelpOption("-h|--help");
CommandArgument projectArgument = app.Argument("<PROJECT>",
"The MSBuild project file to publish. If a project file is not specified," +
" MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file.");
CommandOption frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework to publish for", CommandOptionType.SingleValue);
CommandOption runtimeOption = app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue);
CommandOption outputOption = app.Option("-o|--output <OUTPUT_DIR>", "Path in which to publish the app", CommandOptionType.SingleValue);
CommandOption configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
CommandOption versionSuffixOption = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines the value for the $(VersionSuffix) property in the project", CommandOptionType.SingleValue);
app.OnExecute(() =>
{
List<string> msbuildArgs = new List<string>();
if (!string.IsNullOrEmpty(projectArgument.Value))
{
msbuildArgs.Add(projectArgument.Value);
}
msbuildArgs.Add("/t:Publish");
if (frameworkOption.HasValue())
{
msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}");
}
if (runtimeOption.HasValue())
{
msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}");
}
if (outputOption.HasValue())
{
msbuildArgs.Add($"/p:PublishDir={outputOption.Value()}");
}
if (configurationOption.HasValue())
{
msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}");
}
if (versionSuffixOption.HasValue())
{
msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}");
}
msbuildArgs.AddRange(app.RemainingArguments);
return new MSBuildForwardingApp(msbuildArgs).Execute();
});
return app.Execute(args);
}
}
}

View file

@ -0,0 +1,27 @@
// 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.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public sealed class Publish3Command : TestCommand
{
public Publish3Command()
: base("dotnet")
{
}
public override CommandResult Execute(string args = "")
{
args = $"publish3 {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"publish3 {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}

View file

@ -5,7 +5,7 @@ using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Build3.Tests
namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
public class GivenDotnetMSBuildBuildsProjects : TestBase
{

View file

@ -0,0 +1,41 @@
// 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 System;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Publish3.Tests
{
public class GivenDotnetPublish3PublishesProjects : TestBase
{
[Fact]
public void ItPublishesARunnablePortableApp()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName)
.WithLockFiles();
var testProjectDirectory = testInstance.TestRoot;
new Publish3Command()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0", "publish", $"{testAppName}.dll");
new TestCommand("dotnet")
.ExecuteWithCapturedOutput(outputDll)
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World");
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>fbe4f1d6-ba4c-46d9-8286-4ee4b032d01e</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Cli.Publish3.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,24 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"System.Runtime.Serialization.Primitives": "4.1.1",
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"xunit": "2.2.0-beta3-build3330",
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}