Skip to content

Support dotnet pack file.cs #50168

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 6 commits into
base: main
Choose a base branch
from
Open

Conversation

jjonescz
Copy link
Member

Resolves #49369.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Aug 11, 2025
@jjonescz jjonescz marked this pull request as ready for review August 11, 2025 19:11
@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 19:11
@jjonescz jjonescz requested a review from a team as a code owner August 11, 2025 19:11
@jjonescz jjonescz requested a review from a team August 11, 2025 19:11
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 implements support for dotnet pack file.cs to enable packing file-based programs directly from C# source files. The change allows users to create NuGet packages from standalone C# files without requiring a traditional project file structure.

Key changes:

  • Modified the PackCommand to detect and handle file-based programs using the virtual project building infrastructure
  • Updated command completion descriptions to include C# files as valid inputs
  • Added test coverage for the new functionality

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Cli/dotnet/Commands/Pack/PackCommand.cs Refactored to use CommandFactory pattern and support file-based programs through VirtualProjectBuildingCommand
src/Cli/dotnet/Commands/Pack/PackCommandParser.cs Updated argument name and description to include C# files as valid inputs
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Added PackageOutputPath property and updated runtime config logic to exclude Pack target
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Added comprehensive test for pack functionality and updated virtual project templates
test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs Fixed cast to handle new return type from PackCommand.FromArgs
documentation/general/dotnet-run-file.md Updated documentation to reflect pack support and clarify behavior
test/dotnet.Tests/CompletionTests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh Updated completion description to include C# files
Comments suppressed due to low confidence (1)

Copy link
Member

@zivkan zivkan Aug 13, 2025

Choose a reason for hiding this comment

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

What's the end-to-end scenario for packing file based project?

My understanding is that file based apps are always console apps, is that right? If so, should they be packed as tools, rather than packed as class libraries?

Tools are installed and used with dotnet tool install, whereas class libraries can only be used by PackageReference or equivilent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, tools are the likely scenario. But you could actually pack a library as well if you wanted; like:

#:property OutputType=Library
public class C;

(you just couldn't dotnet run such file-based app)

@@ -807,6 +807,7 @@ public static void WriteProjectFile(
<IncludeProjectNameInArtifactsPaths>false</IncludeProjectNameInArtifactsPaths>
<ArtifactsPath>{EscapeValue(artifactsPath)}</ArtifactsPath>
<PublishDir>artifacts/$(MSBuildProjectName)</PublishDir>
<PackageOutputPath>artifacts/$(MSBuildProjectName)</PackageOutputPath>
Copy link
Member

Choose a reason for hiding this comment

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

Do we have any tests where the user .cs overrides this?

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.

Support packing file-based apps
5 participants