Skip to content

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 24, 2025

The --no-build flag in dotnet 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:

  • Without --no-build: "Project file does not exist." (clear and helpful)
  • With --no-build: "'xyz.csproj' is not a valid project file." (misleading - suggests the file exists but is malformed)

Example

# Clear error message
$ dotnet run --project xyz.csproj
MSBUILD : error MSB1009: Project file does not exist.
Switch: xyz.csproj

# Misleading error message
$ dotnet run --project xyz.csproj --no-build
'xyz.csproj' is not a valid project file.

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 string CmdNonExistentFileErrorDescription.

After the fix

Both cases now show the same clear message:

$ dotnet run --project xyz.csproj --no-build
The provided file path does not exist: xyz.csproj.

$ dotnet run --project xyz.csproj
The provided file path does not exist: xyz.csproj.

Changes

  • RunCommand.cs: Added file existence validation in DiscoverProjectFilePath method
  • Test: Added ItProvidesConsistentErrorMessageWhenProjectFileDoesNotExistWithNoBuild to validate the fix

The 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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet run -v:m (dns block)
    • Triggering command: /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.

@Copilot Copilot AI changed the title [WIP] '--no-build' flag messes with 'dotnet run' error messages Fix --no-build flag error message inconsistency for non-existent project files Jun 24, 2025
@Copilot Copilot AI requested a review from marcpopMSFT June 24, 2025 21:11
Copilot finished work on behalf of marcpopMSFT June 24, 2025 21:11
@marcpopMSFT
Copy link
Member

@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

Copy link
Contributor Author

Copilot AI commented Jun 25, 2025

@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.
...

Fixed both failing tests as suggested:

  1. RunParserCanGetArgumentFromDoubleDash: Created a temporary foo.csproj file for the test so the command finds a valid project
  2. MsbuildInvocationIsCorrect: Changed the test data from "MyProject.csproj" to "HelloWorld.csproj" to match the actual project file being copied from the test asset

Both tests now pass while preserving the original file existence validation functionality. Commit: 47d4222

Copilot finished work on behalf of marcpopMSFT June 25, 2025 22:17
@marcpopMSFT
Copy link
Member

@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?

Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

@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 fo...

Changed the test to use CopyTestAsset("HelloWorld") pattern and removed the manual cleanup code as suggested. The test now follows the same pattern as other tests and runs in its own directory. Commit: 0cdba96

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:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet test --help --configuration Release (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet msbuild /t:Restore /home/REDACTED/work/sdk/sdk/artifacts/tmp/Debug/ItHasAWhySubc---C601CB95/NewtonSoftDependentProject.csproj (dns block)
  • n3kvsblobprodcus335.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet test --property:VsTestUseMSBuildOutput=false -tl:false --logger console;verbosity=detailed (dns block)
  • nn8vsblobprodcus340.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet test --property:VsTestUseMSBuildOutput=false -tl:false --logger console;verbosity=detailed (dns block)
  • vb4vsblobprodcus33.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet test --property:VsTestUseMSBuildOutput=false -tl:false --logger console;verbosity=detailed (dns block)
    • Triggering command: dotnet test test/dotnet.Tests/dotnet.Tests.csproj --no-build (dns block)
  • vwvvsblobprodcus334.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/artifacts/bin/redist/Debug/dotnet/dotnet test --help --configuration Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of marcpopMSFT June 27, 2025 19:08
@marcpopMSFT marcpopMSFT marked this pull request as ready for review July 25, 2025 20:26
@Copilot Copilot AI review requested due to automatic review settings July 25, 2025 20:26
Copy link
Contributor

@Copilot Copilot AI left a 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") || 

@marcpopMSFT marcpopMSFT requested a review from MiYanni July 25, 2025 20:27
@marcpopMSFT
Copy link
Member

Behavior matches what's reported. The tests look right to me. Someone else will have to review since it was my copilot request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'--no-build' flag messes with 'dotnet run' error messages
3 participants