Skip to content

RunCommand prints "Building..." by default if it needs to build #35263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"TestAppThatWaits": {
"commandName": "Project",
"dotnetRunMessages": "false",
"commandLineArgs": "TestAppCommandLineArguments SecondTestAppCommandLineArguments",
"environmentVariables": {
"MyCoolEnvironmentVariableKey": "MyCoolEnvironmentVariableValue"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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")}");
Console.WriteLine($"DOTNET_LAUNCH_PROFILE={Environment.GetEnvironmentVariable("DOTNET_LAUNCH_PROFILE")}");
if (args.Length > 0)
{
Console.WriteLine(args[0]);
}
if (args.Length > 1)
{
Console.WriteLine(args[1]);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"TestAppWithLaunchSettings": {
"commandName": "Project",
"dotnetRunMessages": "false",
"commandLineArgs": "TestAppCommandLineArguments SecondTestAppCommandLineArguments",
"environmentVariables": {
"MyCoolEnvironmentVariableKey": "MyCoolEnvironmentVariableValue"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Cli/dotnet/commands/dotnet-run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int Execute()

if (ShouldBuild)
{
if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase))
if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase) || launchSettings?.DotNetRunMessages is null)
{
Reporter.Output.WriteLine(LocalizableStrings.RunCommandBuilding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,16 @@ static void Main(string[] args)
var str = typeof(LibraryClass).Assembly.GetCustomAttribute<TargetFrameworkAttribute>().FrameworkDisplayName;
Console.WriteLine(str);
}
}";
// disabling "Building..." message
testProject.SourceFiles["Properties/launchSettings.json"] = @"
{
""profiles"": {
""TestApp"": {
""commandName"": ""Project"",
""dotnetRunMessages"": ""false""
}
}
}";
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFrameworkVersion);
var buildCommand = new BuildCommand(testAsset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,15 @@ public class {safeThisName}Class
{
foreach (var kvp in SourceFiles)
{
File.WriteAllText(Path.Combine(targetFolder, kvp.Key), kvp.Value);
var path = Path.Combine(targetFolder, kvp.Key);

var fi = new FileInfo(path);
if (!fi.Directory.Exists)
{
fi.Directory.Create();
}

File.WriteAllText(path, kvp.Value);
}
}

Expand Down
44 changes: 39 additions & 5 deletions src/Tests/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
.WithWorkingDirectory(testProjectDirectory)
.Execute("--framework", ToolsetInfo.CurrentTargetFramework)
.Should().Pass()
.And.HaveStdOut("Hello World!");
.And.HaveStdOutContaining("Hello World!");
}

[Fact]
Expand Down Expand Up @@ -783,9 +783,9 @@ public void ItForwardsEmptyArgumentsToTheApp()
}

[Fact]
public void ItDoesNotPrintBuildingMessageByDefault()
public void ItPrintsBuildingMessageByDefault()
{
var expectedValue = "Building...";
var expectedValue = LocalizableStrings.RunCommandBuilding;
var testAppName = "TestAppSimple";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();
Expand All @@ -796,13 +796,13 @@ public void ItDoesNotPrintBuildingMessageByDefault()
.Should()
.Pass()
.And
.NotHaveStdOutContaining(expectedValue);
.HaveStdOutContaining(expectedValue);
}

[Fact]
public void ItPrintsBuildingMessageIfLaunchSettingHasDotnetRunMessagesSet()
{
var expectedValue = "Building...";
var expectedValue = LocalizableStrings.RunCommandBuilding;
var testAppName = "TestAppWithLaunchSettings";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();
Expand All @@ -816,6 +816,40 @@ public void ItPrintsBuildingMessageIfLaunchSettingHasDotnetRunMessagesSet()
.HaveStdOutContaining(expectedValue);
}

[Fact]
public void ItPrintsBuildingMessageIfNoLaunchSettings()
{
var expectedValue = LocalizableStrings.RunCommandBuilding;
var testAppName = "TestAppSimple";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new DotnetCommand(Log, "run")
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining(expectedValue);
}

[Fact]
public void ItDoesNotPrintBuildingMessageIfLaunchSettingIsFalse()
{
var expectedValue = LocalizableStrings.RunCommandBuilding;
var testAppName = "TestAppWithLaunchSettingsAndDotNetRunMessagesIsFalse";
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
.WithSource();

new DotnetCommand(Log, "run")
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should()
.Pass()
.And
.NotHaveStdOutContaining(expectedValue);
}

[Fact]
public void ItIncludesEnvironmentVariablesSpecifiedInLaunchSettings()
{
Expand Down