From b6174af5119daf3dcdcc747469fc7ff22c1b5f59 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Wed, 4 Apr 2018 15:02:36 -0700 Subject: [PATCH] Implement `dotnet publish --no-build` --- build/DependencyVersions.props | 2 +- .../dotnet-publish/LocalizableStrings.resx | 3 + src/dotnet/commands/dotnet-publish/Program.cs | 5 +- .../dotnet-publish/PublishCommandParser.cs | 7 ++- .../xlf/LocalizableStrings.cs.xlf | 5 ++ .../xlf/LocalizableStrings.de.xlf | 5 ++ .../xlf/LocalizableStrings.es.xlf | 5 ++ .../xlf/LocalizableStrings.fr.xlf | 5 ++ .../xlf/LocalizableStrings.it.xlf | 5 ++ .../xlf/LocalizableStrings.ja.xlf | 5 ++ .../xlf/LocalizableStrings.ko.xlf | 5 ++ .../xlf/LocalizableStrings.pl.xlf | 5 ++ .../xlf/LocalizableStrings.pt-BR.xlf | 5 ++ .../xlf/LocalizableStrings.ru.xlf | 5 ++ .../xlf/LocalizableStrings.tr.xlf | 5 ++ .../xlf/LocalizableStrings.zh-Hans.xlf | 5 ++ .../xlf/LocalizableStrings.zh-Hant.xlf | 5 ++ .../GivenDotnetPublishInvocation.cs | 20 ++++++- .../GivenDotnetPublishPublishesProjects.cs | 56 +++++++++++++++++++ 19 files changed, 152 insertions(+), 6 deletions(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index efbd36959..77f17de57 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -14,7 +14,7 @@ $(MicrosoftCodeAnalysisCSharpPackageVersion) $(MicrosoftCodeAnalysisCSharpPackageVersion) $(MicrosoftCodeAnalysisCSharpPackageVersion) - 2.1.300-preview2-62716-01 + 2.1.300-preview3-62804-06 $(MicrosoftNETSdkPackageVersion) $(MicrosoftAspNetCoreAppPackageVersion) 2.1.300-preview2-20180306-1448279 diff --git a/src/dotnet/commands/dotnet-publish/LocalizableStrings.resx b/src/dotnet/commands/dotnet-publish/LocalizableStrings.resx index e11675be8..93acbf870 100644 --- a/src/dotnet/commands/dotnet-publish/LocalizableStrings.resx +++ b/src/dotnet/commands/dotnet-publish/LocalizableStrings.resx @@ -141,4 +141,7 @@ 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. + + Do not build project before publishing. Implies --no-restore. + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 223e786e7..ed8f3260c 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -43,7 +43,8 @@ namespace Microsoft.DotNet.Tools.Publish msbuildArgs.AddRange(appliedPublishOption.Arguments); - bool noRestore = appliedPublishOption.HasOption("--no-restore"); + bool noRestore = appliedPublishOption.HasOption("--no-restore") + || appliedPublishOption.HasOption("--no-build"); return new PublishCommand( msbuildArgs, @@ -70,4 +71,4 @@ namespace Microsoft.DotNet.Tools.Publish return cmd.Execute(); } } -} \ No newline at end of file +} diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 91d0e0659..56e55e539 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -1,7 +1,6 @@ // 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 System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Tools; @@ -33,6 +32,10 @@ namespace Microsoft.DotNet.Cli Accept.OneOrMoreArguments() .With(name: LocalizableStrings.ManifestOption) .ForwardAsSingle(o => $"-property:TargetManifestFiles={string.Join("%3B", o.Arguments)}")), + Create.Option( + "--no-build", + LocalizableStrings.NoBuildOptionDescription, + Accept.NoArguments().ForwardAs("-property:NoBuild=true")), Create.Option( "--self-contained", LocalizableStrings.SelfContainedOptionDescription, @@ -46,4 +49,4 @@ namespace Microsoft.DotNet.Cli CommonOptions.NoRestoreOption(), CommonOptions.VerbosityOption()); } -} \ No newline at end of file +} diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf index 37b71db9d..f3711ca7d 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.cs.xlf @@ -42,6 +42,11 @@ Publikuje spolu s aplikací modul runtime .NET Core, aby se tento modul nemusel instalovat na cílový počítač. Standardně se nastaví na True, pokud je zadaný identifikátor modulu runtime. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.de.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.de.xlf index 832d56a35..d92f9061d 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.de.xlf @@ -42,6 +42,11 @@ Veröffentlichen Sie die .NET Core-Runtime mit Ihrer Anwendung, damit die Runtime auf dem Zielcomputer nicht installiert werden muss. Der Standardwert ist "true", wenn ein Runtimebezeichner angegeben ist. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.es.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.es.xlf index 779367c21..489c71ca5 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.es.xlf @@ -42,6 +42,11 @@ Publica el tiempo de ejecución de .NET Core con su aplicación para que no sea necesario instalarlo en la máquina de destino. Si se especifica un identificador de tiempo de ejecución, se toma como predeterminado el valor "true". + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.fr.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.fr.xlf index 44a8f8c73..e7f4eb781 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.fr.xlf @@ -42,6 +42,11 @@ Publiez le runtime .NET Core avec votre application pour éviter à l'utilisateur de l'installer sur la machine cible. La valeur par défaut est 'true' si un identificateur de runtime est spécifié. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.it.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.it.xlf index 3e15ff10b..d23757a14 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.it.xlf @@ -42,6 +42,11 @@ Pubblica il runtime di .NET Core con l'applicazione in modo che non sia necessario installarlo nel computer di destinazione. Se si specifica un identificatore di runtime, l'impostazione predefinita è 'true'. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ja.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ja.xlf index 4337b4f66..de8970210 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ja.xlf @@ -42,6 +42,11 @@ ランタイムをターゲット マシンにインストールしなくてもよいよう、.NET Core ランタイムをアプリケーションと一緒に発行します。ランタイム ID が指定される場合、既定の 'true' になります。 + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ko.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ko.xlf index e5f42bc3a..ec06ee9df 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ko.xlf @@ -42,6 +42,11 @@ 런타임은 대상 컴퓨터에 설치할 필요가 없으므로 응용 프로그램과 함께 .NET Core 런타임을 게시합니다. 런타임 식별자가 지정된 경우 기본값은 'true'입니다. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pl.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pl.xlf index 4a51e1e39..98762f398 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pl.xlf @@ -42,6 +42,11 @@ Opublikuj środowisko uruchomieniowe programu .NET Core z aplikacją, aby nie trzeba było go instalować na maszynie docelowej. Domyślnie jest ustawiona wartość „true” w przypadku określenia identyfikatora środowiska uruchomieniowego. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pt-BR.xlf index 81a53b9d7..2bddbbcd2 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.pt-BR.xlf @@ -42,6 +42,11 @@ Publique o tempo de execução .NET Core com seu aplicativo para que o tempo de execução não precise ser instalado no computador de destino. Assumirá 'true' como padrão se um identificador de tempo de execução for especificado. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ru.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ru.xlf index c4ce49b81..4cc8643f4 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.ru.xlf @@ -42,6 +42,11 @@ Опубликуйте среду выполнения .NET Core вместе с приложением, чтобы ее не нужно было устанавливать на целевом компьютере. Если идентификатор среды выполнения указан, значение по умолчанию — true. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.tr.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.tr.xlf index cc3c5ae9d..1acb2c224 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.tr.xlf @@ -42,6 +42,11 @@ Çalışma zamanının hedef makineye yüklenmesine gerek kalmaması için, .NET Core çalışma zamanını uygulamanızla birlikte yayımlayın. Bir çalışma zamanı tanımlayıcısı belirtilmişse, varsayılan olarak 'true' değerine ayarlanır. + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hans.xlf index 64d86e8bb..b19817aa7 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hans.xlf @@ -42,6 +42,11 @@ 随附应用程序发布 .NET Core 运行时,免除在目标计算机上安装运行时的需求。如果指定了运行时标识符,则默认为 “true”。 + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hant.xlf index ad6e74bf6..db7c8c18b 100644 --- a/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet/commands/dotnet-publish/xlf/LocalizableStrings.zh-Hant.xlf @@ -42,6 +42,11 @@ 隨著應用程式一併發行 .NET Core 執行階段,因此不需要在目標電腦上安裝此執行階段。若指定了執行階段識別碼,則預設為 'true'。 + + Do not build project before publishing. Implies --no-restore. + Do not build project before publishing. Implies --no-restore. + + \ No newline at end of file diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index 2eb45a33a..b66155261 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -72,6 +72,23 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests .Be($"{ExpectedPrefix} -nologo -target:Publish{expectedAdditionalArgs}"); } + [Fact] + public void MsbuildInvocationIsCorrectForNoBuild() + { + var msbuildPath = ""; + var command = PublishCommand.FromArgs(new[] { "--no-build" }, msbuildPath); + + command.SeparateRestoreCommand + .Should() + .BeNull(); + + // NOTE --no-build implies no-restore hence no -restore argument to msbuild below. + command.GetProcessStartInfo() + .Arguments + .Should() + .Be($"{ExpectedPrefix} -target:Publish -property:NoBuild=true"); + } + [Theory] [InlineData(new string[] { }, "")] [InlineData(new string[] { "-f", "" }, "-property:TargetFramework=")] @@ -86,6 +103,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--manifest", "" }, "-property:TargetManifestFiles=")] [InlineData(new string[] { "-v", "minimal" }, "-verbosity:minimal")] [InlineData(new string[] { "--verbosity", "minimal" }, "-verbosity:minimal")] + [InlineData(new string[] { "--no-build" }, "-property:NoBuild=true")] public void OptionForwardingIsCorrect(string[] args, string expectedAdditionalArgs) { var expectedArgs = expectedAdditionalArgs.Split(' ', StringSplitOptions.RemoveEmptyEntries); @@ -100,4 +118,4 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests .BeEquivalentTo(expectedArgs); } } -} \ No newline at end of file +} diff --git a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs index aa705a0c2..3152e0a2c 100644 --- a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs +++ b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs @@ -235,5 +235,61 @@ namespace Microsoft.DotNet.Cli.Publish.Tests .Should().Pass() .And.HaveStdOutContaining("Hello World"); } + + [Fact] + public void ItFailsToPublishWithNoBuildIfNotPreviouslyBuilt() + { + var rootPath = TestAssets.CreateTestDirectory().FullName; + + string newArgs = $"console -o \"{rootPath}\""; + new NewCommandShim() + .WithWorkingDirectory(rootPath) + .Execute(newArgs) + .Should().Pass(); + + new PublishCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput("--no-build") + .Should().Fail() + .And.HaveStdOutContaining("MSB3030"); // "Could not copy ___ because it was not found. + } + + [Fact] + public void ItPublishesSuccessfullyWithNoBuildIfPreviouslyBuilt() + { + var rootPath = TestAssets.CreateTestDirectory().FullName; + var rootDir = new DirectoryInfo(rootPath); + + string newArgs = $"console -o \"{rootPath}\" --no-restore"; + new NewCommandShim() + .WithWorkingDirectory(rootPath) + .Execute(newArgs) + .Should() + .Pass(); + + new BuildCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + + new PublishCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput("--no-build") + .Should() + .Pass(); + + var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; + + var outputProgram = rootDir + .GetDirectory("bin", configuration, "netcoreapp2.1", "publish", $"{rootDir.Name}.dll") + .FullName; + + new TestCommand(outputProgram) + .ExecuteWithCapturedOutput() + .Should() + .Pass() + .And.HaveStdOutContaining("Hello World"); + } } }