Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 37f531b

Browse files
committed
Handling an exception that happens when dotnet run is invoked with a file that is not a valid project file. We catch that exception and re-throw it as a GracefulException.
1 parent f4d884a commit 37f531b

18 files changed

+126
-8
lines changed

src/dotnet/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
[assembly: InternalsVisibleTo("dotnet-sln-list.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1717
[assembly: InternalsVisibleTo("dotnet-sln-remove.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1818
[assembly: InternalsVisibleTo("dotnet-msbuild.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
19+
[assembly: InternalsVisibleTo("dotnet-run.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

src/dotnet/commands/dotnet-run/LocalizableStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,7 @@ The current {1} is '{2}'.</value>
196196
<value>An error was encountered when reading launchSettings.json.
197197
{0}</value>
198198
</data>
199+
<data name="RunCommandSpecifiecFileIsNotAValidProject" xml:space="preserve">
200+
<value>'{0}' is not a valid project file.</value>
201+
</data>
199202
</root>

src/dotnet/commands/dotnet-run/RunCommand.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using Microsoft.Build.Evaluation;
9+
using Microsoft.Build.Exceptions;
910
using Microsoft.DotNet.Cli.Utils;
1011
using Microsoft.DotNet.Tools;
1112
using Microsoft.DotNet.Tools.MSBuild;
@@ -39,17 +40,26 @@ public int Start()
3940
EnsureProjectIsBuilt();
4041
}
4142

42-
ICommand runCommand = GetRunCommand();
43-
int launchSettingsApplicationResult = ApplyLaunchProfileSettingsIfNeeded(ref runCommand);
43+
try
44+
{
45+
ICommand runCommand = GetRunCommand();
46+
int launchSettingsApplicationResult = ApplyLaunchProfileSettingsIfNeeded(ref runCommand);
47+
48+
if (launchSettingsApplicationResult != 0)
49+
{
50+
return launchSettingsApplicationResult;
51+
}
4452

45-
if (launchSettingsApplicationResult != 0)
53+
return runCommand
54+
.Execute()
55+
.ExitCode;
56+
}
57+
catch (InvalidProjectFileException e)
4658
{
47-
return launchSettingsApplicationResult;
59+
throw new GracefulException(
60+
string.Format(LocalizableStrings.RunCommandSpecifiecFileIsNotAValidProject, Project),
61+
e);
4862
}
49-
50-
return runCommand
51-
.Execute()
52-
.ExitCode;
5363
}
5464

5565
public RunCommand(string configuration,

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Aktuální {1} je {2}.</target>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Ein ausführbares Projekt sollte ein ausführbares TFM (z.B. netcoreapp2.0) verw
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ El actual {1} es '{2}'.</target>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Le {1} actuel est '{2}'.</target>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Il valore corrente di {1} è '{2}'.</target>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ The current {1} is '{2}'.</source>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

src/dotnet/commands/dotnet-run/xlf/LocalizableStrings.ko.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ The current {1} is '{2}'.</source>
136136
{0}</target>
137137
<note />
138138
</trans-unit>
139+
<trans-unit id="RunCommandSpecifiecFileIsNotAValidProject">
140+
<source>'{0}' is not a valid project file.</source>
141+
<target state="new">'{0}' is not a valid project file.</target>
142+
<note />
143+
</trans-unit>
139144
</body>
140145
</file>
141146
</xliff>

0 commit comments

Comments
 (0)