diff --git a/src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs b/src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs new file mode 100644 index 000000000000..6292216dd517 --- /dev/null +++ b/src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs @@ -0,0 +1,16 @@ +// 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; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello world"); + Console.WriteLine($"MyCoolEnvironmentVariableKey={Environment.GetEnvironmentVariable("MyCoolEnvironmentVariableKey")}"); + } + } +} diff --git a/src/Assets/TestProjects/TestAppWithLaunchSettings/Properties/launchSettings.json b/src/Assets/TestProjects/TestAppWithLaunchSettings/Properties/launchSettings.json new file mode 100644 index 000000000000..d9381bec04f0 --- /dev/null +++ b/src/Assets/TestProjects/TestAppWithLaunchSettings/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "TestAppWithLaunchSettings": { + "commandName": "Project", + "dotnetRunMessages": "true", + "environmentVariables": { + "MyCoolEnvironmentVariableKey": "MyCoolEnvironmentVariableValue" + } + } + } +} \ No newline at end of file diff --git a/src/Assets/TestProjects/TestAppWithLaunchSettings/TestAppWithLaunchSettings.csproj b/src/Assets/TestProjects/TestAppWithLaunchSettings/TestAppWithLaunchSettings.csproj new file mode 100644 index 000000000000..1319a1bcba1f --- /dev/null +++ b/src/Assets/TestProjects/TestAppWithLaunchSettings/TestAppWithLaunchSettings.csproj @@ -0,0 +1,8 @@ + + + + + netcoreapp3.0 + Exe + + \ No newline at end of file diff --git a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs index 681daee24a98..0b0e8bdc108d 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs +++ b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs @@ -5,9 +5,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings { internal interface ILaunchSettingsProvider { - string CommandName { get; } - - LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref ICommand command); + LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model); } } diff --git a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs index 04b9dca3be3b..983faa214605 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs +++ b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs @@ -1,18 +1,21 @@ +// 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. + namespace Microsoft.DotNet.Tools.Run.LaunchSettings { public class LaunchSettingsApplyResult { - public LaunchSettingsApplyResult(bool success, string failureReason, string runAfterLaunch = null) + public LaunchSettingsApplyResult(bool success, string failureReason, ProjectLaunchSettingsModel launchSettings = null) { Success = success; FailureReason = failureReason; - RunAfterLaunch = runAfterLaunch; + LaunchSettings = launchSettings; } public bool Success { get; } public string FailureReason { get; } - public string RunAfterLaunch { get; } + public ProjectLaunchSettingsModel LaunchSettings { get; } } } diff --git a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs index d8f4b5f3c276..1b7bd802c76a 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -1,4 +1,7 @@ -using System; +// 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.Collections.Generic; using System.Linq; using System.Text.Json; @@ -21,7 +24,7 @@ static LaunchSettingsManager() }; } - public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSettingsJsonContents, ref ICommand command, string profileName = null) + public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSettingsJsonContents, string profileName = null) { try { @@ -90,7 +93,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.LaunchProfileHandlerCannotBeLocated, commandName)); } - return provider.TryApplySettings(profileObject, ref command); + return provider.TryGetLaunchSettings(profileObject); } } catch (JsonException ex) diff --git a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsModel.cs b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsModel.cs new file mode 100644 index 000000000000..df50d702ba90 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsModel.cs @@ -0,0 +1,23 @@ +// 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.Collections.Generic; + +namespace Microsoft.DotNet.Tools.Run.LaunchSettings +{ + public class ProjectLaunchSettingsModel + { + public string CommandLineArgs { get; set; } + + public bool LaunchBrowser { get; set; } + + public string LaunchUrl { get; set; } + + public string ApplicationUrl { get; set; } + + public string DotNetRunMessages { get; set; } + + public Dictionary EnvironmentVariables { get; } = new Dictionary(StringComparer.Ordinal); + } +} diff --git a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs index 52f86b4db845..e93e01c17be2 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs +++ b/src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs @@ -1,7 +1,8 @@ -using System; -using System.Collections.Generic; +// 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.Text.Json; -using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Run.LaunchSettings { @@ -11,7 +12,7 @@ internal class ProjectLaunchSettingsProvider : ILaunchSettingsProvider public string CommandName => CommandNameValue; - public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref ICommand command) + public LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model) { var config = new ProjectLaunchSettingsModel(); foreach (var property in model.EnumerateObject()) @@ -52,6 +53,15 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman config.ApplicationUrl = applicationUrlValue; } + else if (string.Equals(property.Name, nameof(ProjectLaunchSettingsModel.DotNetRunMessages), StringComparison.OrdinalIgnoreCase)) + { + if (!TryGetStringValue(property.Value, out var dotNetRunMessages)) + { + return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.CouldNotConvertToString, property.Name)); + } + + config.DotNetRunMessages = dotNetRunMessages; + } else if (string.Equals(property.Name, nameof(ProjectLaunchSettingsModel.EnvironmentVariables), StringComparison.OrdinalIgnoreCase)) { if (property.Value.ValueKind != JsonValueKind.Object) @@ -59,7 +69,7 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.ValueMustBeAnObject, property.Name)); } - foreach(var environmentVariable in property.Value.EnumerateObject()) + foreach (var environmentVariable in property.Value.EnumerateObject()) { if (TryGetStringValue(environmentVariable.Value, out var environmentVariableValue)) { @@ -69,21 +79,7 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman } } - if (!string.IsNullOrEmpty(config.ApplicationUrl)) - { - command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl); - } - - //For now, ignore everything but the environment variables section - - foreach (var entry in config.EnvironmentVariables) - { - string value = Environment.ExpandEnvironmentVariables(entry.Value); - //NOTE: MSBuild variables are not expanded like they are in VS - command.EnvironmentVariable(entry.Key, value); - } - - return new LaunchSettingsApplyResult(true, null, config.LaunchUrl); + return new LaunchSettingsApplyResult(true, null, config); } private static bool TryGetBooleanValue(JsonElement element, out bool value) @@ -136,23 +132,5 @@ private static bool TryGetStringValue(JsonElement element, out string value) return false; } } - - private class ProjectLaunchSettingsModel - { - public ProjectLaunchSettingsModel() - { - EnvironmentVariables = new Dictionary(StringComparer.Ordinal); - } - - public string CommandLineArgs { get; set; } - - public bool LaunchBrowser { get; set; } - - public string LaunchUrl { get; set; } - - public string ApplicationUrl { get; set; } - - public Dictionary EnvironmentVariables { get; } - } } } diff --git a/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx index 24c591290b4d..59f9d4b94494 100644 --- a/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx @@ -147,6 +147,9 @@ The target runtime to run for. + + Building... + The build failed. Fix the build errors and run again. @@ -214,4 +217,4 @@ The current {1} is '{2}'. The property '{0}' must be an object if it is specified. - \ No newline at end of file + diff --git a/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs b/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs index 1bd02d65e6b5..7c54dc4cbfd6 100644 --- a/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-run/RunCommand.cs @@ -8,8 +8,6 @@ using Microsoft.Build.Execution; using Microsoft.Build.Exceptions; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.Run.LaunchSettings; using Microsoft.DotNet.CommandFactory; @@ -41,17 +39,37 @@ public int Execute() { Initialize(); + if (!TryGetLaunchProfileSettingsIfNeeded(out var launchSettings)) + { + return 1; + } + if (ShouldBuild) { + if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase)) + { + Reporter.Output.WriteLine(LocalizableStrings.RunCommandBuilding); + } + EnsureProjectIsBuilt(); } try { ICommand targetCommand = GetTargetCommand(); - if (!ApplyLaunchProfileSettingsIfNeeded(ref targetCommand)) + if (launchSettings != null) { - return 1; + if (!string.IsNullOrEmpty(launchSettings.ApplicationUrl)) + { + targetCommand.EnvironmentVariable("ASPNETCORE_URLS", launchSettings.ApplicationUrl); + } + + foreach (var entry in launchSettings.EnvironmentVariables) + { + string value = Environment.ExpandEnvironmentVariables(entry.Value); + //NOTE: MSBuild variables are not expanded like they are in VS + targetCommand.EnvironmentVariable(entry.Key, value); + } } // Ignore Ctrl-C for the remainder of the command's execution @@ -92,8 +110,9 @@ public RunCommand(string configuration, Interactive = interactive; } - private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) + private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel launchSettingsModel) { + launchSettingsModel = default; if (!UseLaunchProfile) { return true; @@ -117,7 +136,8 @@ private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) if (File.Exists(launchSettingsPath)) { - if (!HasQuietVerbosity) { + if (!HasQuietVerbosity) + { Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); } @@ -126,11 +146,15 @@ private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) try { var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); - var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref targetCommand, LaunchProfile); + var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, LaunchProfile); if (!applyResult.Success) { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); } + else + { + launchSettingsModel = applyResult.LaunchSettings; + } } catch (IOException ex) { @@ -155,7 +179,7 @@ private void EnsureProjectIsBuilt() new RestoringCommand( restoreArgs.Prepend(Project), restoreArgs, - new [] { Project }, + new[] { Project }, NoRestore ).Execute(); diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf index 3d4b5a0bfbbd..4db4cc36cc5b 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf @@ -32,6 +32,11 @@ Hodnotu vlastnosti {0} nejde převést na řetězec. + + Building... + Building... + + The build failed. Fix the build errors and run again. Sestavení se nepovedlo. Opravte v sestavení chyby a spusťte ho znovu. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf index 894850a8306a..44fd789c877d 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf @@ -32,6 +32,11 @@ Der Wert der Eigenschaft "{0}" konnte nicht in eine Zeichenfolge konvertiert werden. + + Building... + Building... + + The build failed. Fix the build errors and run again. Fehler beim Buildvorgang. Beheben Sie die Buildfehler, und versuchen Sie es anschließend noch mal. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf index b0f5cfd3adc8..3fdd4adb282c 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf @@ -32,6 +32,11 @@ No se pudo convertir el valor de la propiedad "{0}" en una cadena. + + Building... + Building... + + The build failed. Fix the build errors and run again. No se pudo llevar a cabo la compilación. Corrija los errores de compilación y vuelva a ejecutar el proyecto. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf index efd4b5464273..454b69ba74b0 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf @@ -32,6 +32,11 @@ Impossible de convertir la valeur de la propriété '{0}' en chaîne. + + Building... + Building... + + The build failed. Fix the build errors and run again. La build a échoué. Corrigez les erreurs de la build et réexécutez-la. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf index a50fd3663ea2..a6c18ea6b1f6 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf @@ -32,6 +32,11 @@ Non è stato possibile convertire il valore della proprietà '{0}' in una stringa. + + Building... + Building... + + The build failed. Fix the build errors and run again. La compilazione non è riuscita. Correggere gli errori di compilazione e ripetere l'esecuzione. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf index f43c361d0475..39c8e8d6632c 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf @@ -32,6 +32,11 @@ プロパティ '{0}' の値を文字列に変換できませんでした。 + + Building... + Building... + + The build failed. Fix the build errors and run again. ビルドに失敗しました。ビルド エラーを修正して、もう一度実行してください。 diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf index 0a141e6b14b1..6bce6cdf9a98 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf @@ -32,6 +32,11 @@ '{0}' 속성 값을 문자열로 변환할 수 없습니다. + + Building... + Building... + + The build failed. Fix the build errors and run again. 빌드하지 못했습니다. 빌드 오류를 수정하고 다시 실행하세요. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf index 1f196db2c3ea..f7d703ccba64 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pl.xlf @@ -32,6 +32,11 @@ Nie można przekonwertować wartości właściwości „{0}” na ciąg. + + Building... + Building... + + The build failed. Fix the build errors and run again. Kompilacja nie powiodła się. Napraw błędy kompilacji i uruchom ją ponownie. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf index eaf3313d4271..c2ad38c4d521 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.pt-BR.xlf @@ -32,6 +32,11 @@ Não foi possível converter o valor da propriedade '{0}' em uma cadeia de caracteres. + + Building... + Building... + + The build failed. Fix the build errors and run again. Ocorreu uma falha no build. Corrija os erros de build e execute novamente. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf index ae48a6218aa2..3aad37723a9a 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ru.xlf @@ -32,6 +32,11 @@ Не удалось преобразовать значение свойства "{0}" в строку. + + Building... + Building... + + The build failed. Fix the build errors and run again. Ошибка сборки. Устраните ошибки сборки и повторите попытку. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf index b15f6a6ec8d8..eac14f47d350 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.tr.xlf @@ -32,6 +32,11 @@ '{0}' özelliğinin değeri dizeye dönüştürülemedi. + + Building... + Building... + + The build failed. Fix the build errors and run again. Derleme başarısız oldu. Derleme hatalarını düzeltip yeniden çalıştırın. diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf index d29d59941f4a..a53e764a4d99 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hans.xlf @@ -32,6 +32,11 @@ 无法将属性“{0}”的值转换为字符串。 + + Building... + Building... + + The build failed. Fix the build errors and run again. 生成失败。请修复生成错误并重新运行。 diff --git a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf index 1e96ecaa985e..c3a6053a9615 100644 --- a/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-run/xlf/LocalizableStrings.zh-Hant.xlf @@ -32,6 +32,11 @@ 無法將屬性 '{0}' 的值轉換為字串。 + + Building... + Building... + + The build failed. Fix the build errors and run again. 建置失敗。請修正建置錯誤後,再執行一次。 diff --git a/src/Tests/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/src/Tests/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index ebddac12aed2..0ac10a8d886b 100644 --- a/src/Tests/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/src/Tests/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -572,5 +572,56 @@ public void ItForwardsEmptyArgumentsToTheApp() .And .HaveStdOutContaining($"0 = a{Environment.NewLine}1 = {Environment.NewLine}2 = c"); } + + [Fact] + public void ItDoesNotPrintBuildingMessageByDefault() + { + var expectedValue = "Building..."; + var testAppName = "TestAppSimple"; + var testInstance = _testAssetsManager.CopyTestAsset(testAppName) + .WithSource(); + + new DotnetCommand(Log, "run") + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should() + .Pass() + .And + .NotHaveStdOutContaining(expectedValue); + } + + [Fact] + public void ItPrintsBuildingMessageIfLaunchSettingHasDotnetRunMessagesSet() + { + var expectedValue = "Building..."; + var testAppName = "TestAppWithLaunchSettings"; + var testInstance = _testAssetsManager.CopyTestAsset(testAppName) + .WithSource(); + + new DotnetCommand(Log, "run") + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should() + .Pass() + .And + .HaveStdOutContaining(expectedValue); + } + + [Fact] + public void ItIncludesEnvironmentVariablesSpecifiedInLaunchSettings() + { + var expectedValue = "MyCoolEnvironmentVariableKey=MyCoolEnvironmentVariableValue"; + var testAppName = "TestAppWithLaunchSettings"; + var testInstance = _testAssetsManager.CopyTestAsset(testAppName) + .WithSource(); + + new DotnetCommand(Log, "run") + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should() + .Pass() + .And + .HaveStdOutContaining(expectedValue); + } } }