Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

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

  • CSharpCompilerCommand.cs: Gate the obj→bin copy with exitCode == 0 check
  • RunFileTests.cs: Add CscOnly_CompilationFailure_NoCopyToBin test verifying bin dll is not updated after failed compilation

The fix ensures failed builds don't produce or modify output artifacts:

// Process the response.
var exitCode = ProcessBuildResponse(responseTask.Result, out fallbackToNormalBuild);

// Copy from obj to bin only if the build succeeded.
if (exitCode == 0 &&
    BuildResultFile != null &&
    CSharpCommandLineParser.Default.Parse(...) is { OutputFileName: { } outputFileName } parsedArgs)
{
    // ... copy logic
}
Original prompt

Let's modify CSharpCompilerCommand to skip copying the obj dll to bin directory if the build fails (it's an unnecessary work and can lead to spurious errors, for example if the source file was not even produced by roslyn due to compilation errors - add a test for that too)


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

Copilot AI self-assigned this Nov 7, 2025
Copilot AI and others added 2 commits November 7, 2025 13:36
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]>
Copilot AI changed the title [WIP] Update CSharpCompilerCommand to skip copying obj dll on build failure Skip obj→bin copy on build failure in CSharpCompilerCommand Nov 7, 2025
Copilot AI requested a review from jjonescz November 7, 2025 13:42
Copilot finished work on behalf of jjonescz November 7, 2025 13:42
@jjonescz jjonescz marked this pull request as ready for review November 7, 2025 17:25
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Nov 7, 2025
@jjonescz jjonescz requested review from a team and Copilot November 7, 2025 17:25
Copy link
Contributor

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 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.cs to only copy files when exitCode == 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

@RikkiGibson
Copy link
Member

Is there a specific issue that is being solved by this PR? If so, please link to it.

@jjonescz
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants