-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix --no-build flag error message inconsistency for non-existent project files #49544
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
base: main
Are you sure you want to change the base?
Conversation
…ect files Co-authored-by: marcpopMSFT <[email protected]>
@copilot there are two failing tests that appear to use the project flag with a nonexistent project and are now hitting this new error. The tests are valid so the best solution is to workaround this. For RunParserCanGetArgumentFromDoubleDash, I would just create a project called foo.csproj so that the command finds a valid project when it runs. For MsbuildInvocationIsCorrect, it expects MyProject.csproj but I believe it's copying in HelloWorld.csproj. I would try changing the data driven test to match |
Co-authored-by: marcpopMSFT <[email protected]>
Fixed both failing tests as suggested:
Both tests now pass while preserving the original file existence validation functionality. Commit: 47d4222 |
@copilot for test RunParserCanGetArgumentFromDoubleDash, can you use CopyTestAsset("HelloWorld") like other tests and you don't need to clean up the project after as we run each test in a different folder? |
…Dash test Co-authored-by: marcpopMSFT <[email protected]>
Changed the test to use Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an inconsistency in error messages when running dotnet run
with the --no-build
flag on non-existent project files. Previously, the error messages differed between using --no-build
and not using it, causing confusion for developers.
- Added file existence validation in the
DiscoverProjectFilePath
method to provide consistent error messaging - Updated tests to use valid project paths and added a new test to verify the fix
- Ensures both build and no-build scenarios show the same clear error message for missing project files
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Cli/dotnet/Commands/Run/RunCommand.cs | Added file existence check before project loading to provide consistent error messages |
test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs | Added test case to verify consistent error messaging with --no-build flag |
test/dotnet.Tests/CommandTests/Run/RunParserTests.cs | Updated test to use a valid project file path instead of non-existent file |
test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs | Updated test parameter to reference valid HelloWorld.csproj instead of MyProject.csproj |
Comments suppressed due to low confidence (1)
test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs:1031
- The error message validation is too broad and fragile. Instead of checking for multiple generic phrases, the test should verify the exact expected error message format using the
CmdNonExistentFileErrorDescription
localized string to ensure the fix works correctly.
var hasExpectedErrorMessage = stderr.Contains("does not exist") ||
test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs
Outdated
Show resolved
Hide resolved
Behavior matches what's reported. The tests look right to me. Someone else will have to review since it was my copilot request. |
The
--no-build
flag indotnet run
was producing misleading error messages when project files don't exist. This created confusion for developers who would see different error messages depending on whether they used--no-build
or not.Problem
When running
dotnet run
with a non-existent project file:--no-build
: "Project file does not exist." (clear and helpful)--no-build
: "'xyz.csproj' is not a valid project file." (misleading - suggests the file exists but is malformed)Example
Solution
Added a file existence check in the
DiscoverProjectFilePath
method before attempting to load the project. When a specified project file doesn't exist, both code paths now provide a consistent, clear error message using the existing localized stringCmdNonExistentFileErrorDescription
.After the fix
Both cases now show the same clear message:
Changes
RunCommand.cs
: Added file existence validation inDiscoverProjectFilePath
methodItProvidesConsistentErrorMessageWhenProjectFileDoesNotExistWithNoBuild
to validate the fixThe fix is minimal and surgical - it only adds a file existence check when a project file path is explicitly provided and doesn't exist, ensuring consistent error messaging across both build and no-build scenarios.
Fixes #24591.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
4m6vsblobprodcus384.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)4zjvsblobprodcus390.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)ajhvsblobprodcus363.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)c78vsblobprodcus322.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)d0svsblobprodcus381.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)jd4vsblobprodcus366.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js
(dns block)josvsblobprodcus372.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)k0ivsblobprodcus356.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)k4kvsblobprodcus344.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)nn8vsblobprodcus340.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)pe3vsblobprodcus354.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)rcxvsblobprodcus328.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)ukkvsblobprodcus352.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)yttvsblobprodcus357.vsblob.vsassets.io
/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m
(dns block)/home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -p /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItWarnsWhenSh---7BBD1F37/MSBuildTestApp.csproj
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.