From d4f6144355886e5d331bb744ba5b6ff13b4c4fec Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 23 Sep 2016 11:09:15 -0500 Subject: [PATCH 1/4] Update Microsoft.NETCore.Sdk to 1.0.0-alpha-20160921-4. --- TestAssets/TestProjects/MSBuildTestApp/project.json | 2 +- .../commands/dotnet-new/CSharp_MSBuild/project.json.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TestAssets/TestProjects/MSBuildTestApp/project.json b/TestAssets/TestProjects/MSBuildTestApp/project.json index 3087945e1..028dfb88a 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/project.json +++ b/TestAssets/TestProjects/MSBuildTestApp/project.json @@ -2,7 +2,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160914-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160921-4", "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" diff --git a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template index 897ee0fae..bc91b1a8b 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template +++ b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template @@ -3,7 +3,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160914-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160921-4", "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" From eed29be806179c3b9034326fb0728d4dbfbdbece Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 23 Sep 2016 11:11:44 -0500 Subject: [PATCH 2/4] Add `dotnet publish3` command. --- Microsoft.DotNet.Cli.sln | 19 +++++ src/dotnet/Program.cs | 2 + .../commands/dotnet-publish3/Program.cs | 78 +++++++++++++++++++ .../Commands/Publish3Command.cs | 27 +++++++ .../GivenDotnetMSBuildBuildsProjects.cs | 2 +- .../GivenDotnetPublish3PublishesProjects.cs | 41 ++++++++++ .../dotnet-publish3.Tests.xproj | 21 +++++ test/dotnet-publish3.Tests/project.json | 24 ++++++ 8 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 src/dotnet/commands/dotnet-publish3/Program.cs create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/Publish3Command.cs create mode 100644 test/dotnet-publish3.Tests/GivenDotnetPublish3PublishesProjects.cs create mode 100644 test/dotnet-publish3.Tests/dotnet-publish3.Tests.xproj create mode 100644 test/dotnet-publish3.Tests/project.json diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 9cf7f60f3..7840b9296 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -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 diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index f7ddc514a..c31ea5ae5 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -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, diff --git a/src/dotnet/commands/dotnet-publish3/Program.cs b/src/dotnet/commands/dotnet-publish3/Program.cs new file mode 100644 index 000000000..10c39c69e --- /dev/null +++ b/src/dotnet/commands/dotnet-publish3/Program.cs @@ -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("", + "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 ", "Target framework to publish for", CommandOptionType.SingleValue); + CommandOption runtimeOption = app.Option("-r|--runtime ", "Target runtime to publish for", CommandOptionType.SingleValue); + CommandOption outputOption = app.Option("-o|--output ", "Path in which to publish the app", CommandOptionType.SingleValue); + CommandOption configurationOption = app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); + CommandOption versionSuffixOption = app.Option("--version-suffix ", "Defines the value for the $(VersionSuffix) property in the project", CommandOptionType.SingleValue); + + app.OnExecute(() => + { + List msbuildArgs = new List(); + + 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); + } + } +} diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/Publish3Command.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/Publish3Command.cs new file mode 100644 index 000000000..1d0aa6548 --- /dev/null +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/Publish3Command.cs @@ -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); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index 95379d3cf..e79103b85 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -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 { diff --git a/test/dotnet-publish3.Tests/GivenDotnetPublish3PublishesProjects.cs b/test/dotnet-publish3.Tests/GivenDotnetPublish3PublishesProjects.cs new file mode 100644 index 000000000..c74f525ab --- /dev/null +++ b/test/dotnet-publish3.Tests/GivenDotnetPublish3PublishesProjects.cs @@ -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"); + } + } +} diff --git a/test/dotnet-publish3.Tests/dotnet-publish3.Tests.xproj b/test/dotnet-publish3.Tests/dotnet-publish3.Tests.xproj new file mode 100644 index 000000000..9fadfd0d3 --- /dev/null +++ b/test/dotnet-publish3.Tests/dotnet-publish3.Tests.xproj @@ -0,0 +1,21 @@ + + + + 14.0.23107 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + fbe4f1d6-ba4c-46d9-8286-4ee4b032d01e + Microsoft.DotNet.Cli.Publish3.Tests + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin + + + 2.0 + + + + + + \ No newline at end of file diff --git a/test/dotnet-publish3.Tests/project.json b/test/dotnet-publish3.Tests/project.json new file mode 100644 index 000000000..3ee83c3ca --- /dev/null +++ b/test/dotnet-publish3.Tests/project.json @@ -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" +} From 66fbd6f2780d53138510507e1035f6a98db613d0 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 23 Sep 2016 16:14:03 -0500 Subject: [PATCH 3/4] Update Microsoft.NETCore.Sdk to 1.0.0-alpha-20160923-4. --- TestAssets/TestProjects/MSBuildTestApp/project.json | 2 +- .../commands/dotnet-new/CSharp_MSBuild/project.json.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TestAssets/TestProjects/MSBuildTestApp/project.json b/TestAssets/TestProjects/MSBuildTestApp/project.json index 028dfb88a..a228cd853 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/project.json +++ b/TestAssets/TestProjects/MSBuildTestApp/project.json @@ -2,7 +2,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160921-4", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160923-4", "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" diff --git a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template index bc91b1a8b..d744ca5ff 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template +++ b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template @@ -3,7 +3,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160921-4", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160923-4", "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" From fce4b9044aec2f0fe8d20e94b114b62217e370d9 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 23 Sep 2016 16:53:57 -0500 Subject: [PATCH 4/4] Respond to PR feedback. --- .../commands/dotnet-publish3/Program.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish3/Program.cs b/src/dotnet/commands/dotnet-publish3/Program.cs index 10c39c69e..fd529c677 100644 --- a/src/dotnet/commands/dotnet-publish3/Program.cs +++ b/src/dotnet/commands/dotnet-publish3/Program.cs @@ -22,14 +22,28 @@ namespace Microsoft.DotNet.Tools.Publish3 app.HelpOption("-h|--help"); CommandArgument projectArgument = app.Argument("", - "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."); + "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 ", "Target framework to publish for", CommandOptionType.SingleValue); - CommandOption runtimeOption = app.Option("-r|--runtime ", "Target runtime to publish for", CommandOptionType.SingleValue); - CommandOption outputOption = app.Option("-o|--output ", "Path in which to publish the app", CommandOptionType.SingleValue); - CommandOption configurationOption = app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); - CommandOption versionSuffixOption = app.Option("--version-suffix ", "Defines the value for the $(VersionSuffix) property in the project", CommandOptionType.SingleValue); + CommandOption frameworkOption = app.Option( + "-f|--framework ", "Target framework to publish for", + CommandOptionType.SingleValue); + + CommandOption runtimeOption = app.Option( + "-r|--runtime ", "Target runtime to publish for. The default is to publish a portable application.", + CommandOptionType.SingleValue); + + CommandOption outputOption = app.Option( + "-o|--output ", "Path in which to publish the app", + CommandOptionType.SingleValue); + + CommandOption configurationOption = app.Option( + "-c|--configuration ", "Configuration under which to build", + CommandOptionType.SingleValue); + + CommandOption versionSuffixOption = app.Option( + "--version-suffix ", "Defines the value for the $(VersionSuffix) property in the project", + CommandOptionType.SingleValue); app.OnExecute(() => {