Skip to content

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Sep 30, 2025

Description and customer impact

Fixes #51064.

This fixes a regression which broke file-based libraries (that's not a mainline scenario for file-based apps, but it's commonly used for example when testing out compiler features or creating minimal bug repros - that's also how I discovered the issue).

Regression

Yes, worked in prior .NET 10 previews.

Risk

Low, this is a small change, with lots of unit testing (pre-existing tests for the mainline dotnet run app.cs behavior and new tests for the library behavior which regressed).

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Sep 30, 2025
@jjonescz jjonescz requested review from a team and Copilot September 30, 2025 13: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 issue where building file-based libraries would cause errors. The fix changes how run properties are extracted from project instances, allowing for graceful handling when a project cannot be run (like library projects).

Key changes:

  • Modified RunProperties to use a try-pattern method that can fail gracefully
  • Updated the caching logic to handle cases where run properties cannot be extracted
  • Added comprehensive test coverage for building library projects

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Cli/dotnet/Commands/Run/RunProperties.cs Refactored to use try-pattern for extracting run properties from projects
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Updated to handle null run properties when caching and added debug logging
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Added test case to verify library projects can be built without errors

@jjonescz
Copy link
Member Author

jjonescz commented Oct 2, 2025

@RikkiGibson @MiYanni for reviews, thanks

@jjonescz
Copy link
Member Author

jjonescz commented Oct 6, 2025

@RikkiGibson for a review, thanks

TargetFrameworkVersion: project.GetPropertyValue("TargetFrameworkVersion"));

if (string.IsNullOrEmpty(result.Command))
return !string.IsNullOrEmpty(result.Command);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little strange for result to contain non-null when the return value is false.

return !string.IsNullOrEmpty(result.Command);
}

internal static RunProperties FromProject(ProjectInstance project)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a call site of FromProject in src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs:308 is reimplementing some aspects of FromProject. It doesn't seem like it would lead to incorrect behavior, but, thought I would call it out anyway.

.Execute()
.Should().Pass();

new DotnetCommand(Log, "run", "winexe.cs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This question isn't really relevant to the fix, but..
What wizardry are you doing to get console output to actually flow out when running a winexe? If I make a new console app from template, change OutputType to WinExe, and dotnet run the project, I don't get any output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output from WinExe is visible when redirected, e.g., dotnet run winexe.cs > out.txt works. And the test utility redirects the output under the hood.

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 Servicing-approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants