Skip to content

Commit 1010968

Browse files
[release/10.0.1xx] Fix some error messages in dotnet test (#50406)
1 parent 8357cfe commit 1010968

23 files changed

+308
-99
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,10 +1775,11 @@ The default is to publish a framework-dependent application.</value>
17751775
<value>Couldn't find a project to run. Ensure a project exists in {0}, or pass the path to the project using {1}.</value>
17761776
</data>
17771777
<data name="RunCommandExceptionUnableToRun" xml:space="preserve">
1778-
<value>Unable to run your project.
1779-
Ensure you have a runnable project type and ensure '{0}' supports this project.
1780-
A runnable project should target a runnable TFM (for instance, net5.0) and have OutputType 'Exe'.
1781-
The current {1} is '{2}'.</value>
1778+
<value>Unable to proceed with project '{0}'.
1779+
Ensure you have a runnable project type.
1780+
A runnable project should target a runnable TFM (for instance, net{1}) and have OutputType 'Exe'.
1781+
The current OutputType is '{2}'.</value>
1782+
<comment>{0} is project file path. {1} is dotnet framework version. {2} is the project output type.{Locked="OutputType"}{Locked="Exe"}</comment>
17821783
</data>
17831784
<data name="RunCommandExceptionUnableToRunSpecifyFramework" xml:space="preserve">
17841785
<value>Unable to run your project

src/Cli/dotnet/Commands/Run/RunCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ internal static void ThrowUnableToRunError(ProjectInstance project)
511511
throw new GracefulException(
512512
string.Format(
513513
CliCommandStrings.RunCommandExceptionUnableToRun,
514-
"dotnet run",
515-
"OutputType",
514+
project.GetPropertyValue("MSBuildProjectFullPath"),
515+
Product.TargetFrameworkVersion,
516516
project.GetPropertyValue("OutputType")));
517517
}
518518

src/Cli/dotnet/Commands/Test/SolutionAndProjectUtility.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.CommandLine;
54
using System.Diagnostics;
65
using Microsoft.Build.Evaluation;
76
using Microsoft.Build.Execution;
@@ -230,23 +229,37 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
230229
}
231230

232231
string targetFramework = project.GetPropertyValue(ProjectProperties.TargetFramework);
233-
RunProperties runProperties = GetRunProperties(project, loggers);
232+
string projectFullPath = project.GetPropertyValue(ProjectProperties.ProjectFullPath);
233+
234234

235-
// dotnet run throws the same if RunCommand is null or empty.
236-
// In dotnet test, we are additionally checking that RunCommand is not dll.
237-
// In any "default" scenario, RunCommand is never dll.
238-
// If we found it to be dll, that is user explicitly setting RunCommand incorrectly.
239-
if (string.IsNullOrEmpty(runProperties.Command) || runProperties.Command.HasExtension(CliConstants.DLLExtension))
235+
// Only get run properties if IsTestingPlatformApplication is true
236+
RunProperties runProperties;
237+
if (isTestingPlatformApplication)
240238
{
241-
throw new GracefulException(
242-
string.Format(
243-
CliCommandStrings.RunCommandExceptionUnableToRun,
244-
"dotnet test",
245-
"OutputType",
246-
project.GetPropertyValue("OutputType")));
247-
}
239+
runProperties = GetRunProperties(project, loggers);
248240

249-
string projectFullPath = project.GetPropertyValue(ProjectProperties.ProjectFullPath);
241+
// dotnet run throws the same if RunCommand is null or empty.
242+
// In dotnet test, we are additionally checking that RunCommand is not dll.
243+
// In any "default" scenario, RunCommand is never dll.
244+
// If we found it to be dll, that is user explicitly setting RunCommand incorrectly.
245+
if (string.IsNullOrEmpty(runProperties.Command) || runProperties.Command.HasExtension(CliConstants.DLLExtension))
246+
{
247+
throw new GracefulException(
248+
string.Format(
249+
CliCommandStrings.RunCommandExceptionUnableToRun,
250+
projectFullPath,
251+
Product.TargetFrameworkVersion,
252+
project.GetPropertyValue("OutputType")));
253+
}
254+
}
255+
else
256+
{
257+
// For VSTest test projects, create minimal RunProperties
258+
runProperties = new RunProperties(
259+
project.GetPropertyValue(ProjectProperties.TargetPath),
260+
null,
261+
null);
262+
}
250263

251264
// TODO: Support --launch-profile and pass it here.
252265
var launchSettings = TryGetLaunchProfileSettings(Path.GetDirectoryName(projectFullPath)!, Path.GetFileNameWithoutExtension(projectFullPath), project.GetPropertyValue(ProjectProperties.AppDesignerFolder), buildOptions, profileName: null);

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)