-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Skip obj→bin copy on build failure in CSharpCompilerCommand #51614
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: release/10.0.2xx
Are you sure you want to change the base?
Conversation
Modified CSharpCompilerCommand to only copy the obj dll to bin when exitCode == 0. Added test CscOnly_CompilationFailure_NoCopyToBin to verify bin dll is not updated on failure. Co-authored-by: jjonescz <[email protected]>
Removed unnecessary Thread.Sleep(100) from the test as we're comparing timestamps for equality, not testing for differences after a delay. Co-authored-by: jjonescz <[email protected]>
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 adds a safeguard to prevent copying DLL files from the obj directory to the bin directory when C# compilation fails. The change ensures that spurious errors don't occur from attempting to copy non-existent or incomplete DLL files after compilation errors.
Key Changes
- Modified the copy logic in
CSharpCompilerCommand.csto only copy files whenexitCode == 0 - Added comprehensive test coverage for the compilation failure scenario
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.cs | Added exit code check to prevent copying DLLs when compilation fails |
| test/dotnet.Tests/CommandTests/Run/RunFileTests.cs | Added test to verify DLLs are not copied when compilation fails |
|
Is there a specific issue that is being solved by this PR? If so, please link to it. |
|
There is not an existing issue afaik; I noticed the problem while working on another PR. The added test has the "repro" for the issue though. |
CSharpCompilerCommand.Execute()was copying the obj dll to bin regardless of build success, causing unnecessary work and potential errors when the dll doesn't exist due to compilation failures.Changes
exitCode == 0checkCscOnly_CompilationFailure_NoCopyToBintest verifying bin dll is not updated after failed compilationThe fix ensures failed builds don't produce or modify output artifacts:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.