Skip to content

Add --OutputFileNamesWithoutVersion option to dotnet pack#53781

Closed
apurvghai wants to merge 1 commit intodotnet:mainfrom
apurvghai:users/apurvgh/supportVersionLessParameter
Closed

Add --OutputFileNamesWithoutVersion option to dotnet pack#53781
apurvghai wants to merge 1 commit intodotnet:mainfrom
apurvghai:users/apurvgh/supportVersionLessParameter

Conversation

@apurvghai
Copy link
Copy Markdown

Description:

This PR exposes the --OutputFileNamesWithoutVersion option in the dotnet pack CLI, matching the existing NuGet
-OutputFileNamesWithoutVersion switch.

What it does

When specified, the output .nupkg filename omits the version — e.g., MyPackage.nupkg instead of MyPackage.1.0.0.nupkg.

How it works

  • MSBuild path (project files): Forwards -property:OutputFileNamesWithoutVersion=true to MSBuild, which NuGet's
    Pack.targets already consumes.
  • NuSpec path (.nuspec files): Sets PackArgs.OutputFileNamesWithoutVersion, which flows through
    PackCommandRunner.GetOutputFileName(excludeVersion: true).

Changes

  • PackCommandDefinition.cs — Added OutputFileNamesWithoutVersionOption (bool, zero-arity flag)
  • PackCommand.cs — Wired option into PackArgs for the nuspec code path
  • CommandDefinitionStrings.resx + XLF files — Added localized description string
  • PackTests.cs — Added tests for both MSBuild and nuspec paths

For more details, see #53780

Copilot AI review requested due to automatic review settings April 9, 2026 15:09
@apurvghai apurvghai requested a review from a team as a code owner April 9, 2026 15:09
@apurvghai
Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Microsoft"

Copy link
Copy Markdown
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

Exposes NuGet’s “versionless output filename” behavior as a first-class dotnet pack option, supporting both MSBuild-based packing (project files) and the .nuspec pack path.

Changes:

  • Added a new dotnet pack flag that forwards OutputFileNamesWithoutVersion=true to MSBuild and populates PackArgs.OutputFileNamesWithoutVersion for .nuspec packing.
  • Added localized help text for the new option.
  • Added tests covering both MSBuild and .nuspec packing scenarios.

Reviewed changes

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

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Pack/PackTests.cs Adds tests verifying versionless .nupkg naming for both MSBuild and .nuspec pack paths.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Pack/PackCommandDefinition.cs Adds the new CLI option and forwards it as an MSBuild property.
src/Cli/dotnet/Commands/Pack/PackCommand.cs Wires the option into PackArgs for the .nuspec pack code path.
src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx Adds the option description string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.fr.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.it.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ja.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ko.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pl.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pt-BR.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ru.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.tr.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hans.xlf Adds localization entry for the new option description.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hant.xlf Adds localization entry for the new option description.

Comment on lines +54 to +58
public readonly Option<bool> OutputFileNamesWithoutVersionOption = new Option<bool>("--OutputFileNamesWithoutVersion")
{
Description = CommandDefinitionStrings.PackCmdOutputFileNamesWithoutVersionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:OutputFileNamesWithoutVersion=true");
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The new option name uses PascalCase (--OutputFileNamesWithoutVersion), which is inconsistent with the established dotnet pack/CLI long-option naming in this command (e.g., --no-build, --include-symbols, --output). Consider switching to a kebab-case long option (e.g., --output-file-names-without-version) and optionally keeping the PascalCase form as an alias if you need to mirror NuGet’s switch name.

Copilot uses AI. Check for mistakes.
@baronfel
Copy link
Copy Markdown
Member

baronfel commented Apr 9, 2026

We likely won't take this as-is - option names that are multiple words should use Unix-style kebab-casing for their names, like --output-file-names-without-version. In addition, this feature can already be done easily using the existing -p support for passing properties to MSBuild - we don't like to make dedicated options unless they serve some better UX around an experience that is currently-possible-but-hard-to-use. Aligning directly to the CLI schemes of nuget.exe, msbuild.exe or other older tooling is not a goal of the dotnet CLI.

@nkolev92
Copy link
Copy Markdown
Contributor

nkolev92 commented Apr 9, 2026

I agree with @baronfel overall.

There's also the aspect of, I don't necessarily think this is a best practice or even a good to be frank, so I don't want to perpetuate the usage of this option and instead have customers move to a versioned nupkg.

@apurvghai
Copy link
Copy Markdown
Author

apurvghai commented Apr 9, 2026

Yes, @baronfel and I discussed. In general, I think the comment makes perfect sense. However, there are scenarios, where the new file names are a problem. The fact NuGet pack supported those, the change was trying to support backward compatibility.

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.

4 participants