File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
src/Cli/dotnet/Commands/Run
test/dotnet.Tests/CommandTests/Run Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -459,6 +459,12 @@ private static void ThrowUnableToRunError(ProjectInstance project)
459
459
? TryFindSingleProjectInDirectory ( projectFileOrDirectoryPath )
460
460
: projectFileOrDirectoryPath ;
461
461
462
+ // Check if the project file actually exists when it's specified as a direct file path
463
+ if ( projectFilePath is not null && ! emptyProjectOption && ! File . Exists ( projectFilePath ) )
464
+ {
465
+ throw new GracefulException ( CliCommandStrings . CmdNonExistentFileErrorDescription , projectFilePath ) ;
466
+ }
467
+
462
468
// If no project exists in the directory and no --project was given,
463
469
// try to resolve an entry-point file instead.
464
470
entryPointFilePath = projectFilePath is null && emptyProjectOption
Original file line number Diff line number Diff line change @@ -987,5 +987,33 @@ public void EnvOptionNotAppliedToBuild()
987
987
. And
988
988
. HaveStdOutContaining ( "env: Configuration=XYZ" ) ;
989
989
}
990
+
991
+ [ Fact ]
992
+ public void ItProvidesConsistentErrorMessageWhenProjectFileDoesNotExistWithNoBuild ( )
993
+ {
994
+ var tempDir = _testAssetsManager . CreateTestDirectory ( ) ;
995
+ var nonExistentProject = Path . Combine ( tempDir . Path , "nonexistent.csproj" ) ;
996
+
997
+ var result = new DotnetCommand ( Log , "run" )
998
+ . WithWorkingDirectory ( tempDir . Path )
999
+ . Execute ( "--project" , nonExistentProject , "--no-build" ) ;
1000
+
1001
+ result . Should ( ) . Fail ( ) ;
1002
+ if ( ! TestContext . IsLocalized ( ) )
1003
+ {
1004
+ // After the fix, we should get a clear error message about the file not existing
1005
+ var stderr = result . StdErr ;
1006
+
1007
+ Log . WriteLine ( $ "Actual stderr: '{ stderr } '") ;
1008
+
1009
+ // Should provide a clear error message about the project file not existing
1010
+ var hasExpectedErrorMessage = stderr . Contains ( "does not exist" ) ||
1011
+ stderr . Contains ( "not found" ) ||
1012
+ stderr . Contains ( "cannot find" ) ||
1013
+ stderr . Contains ( "could not find" ) ;
1014
+
1015
+ hasExpectedErrorMessage . Should ( ) . BeTrue ( $ "Expected error message to clearly indicate file doesn't exist, but got: { stderr } ") ;
1016
+ }
1017
+ }
990
1018
}
991
1019
}
You can’t perform that action at this time.
0 commit comments