Skip to content

Better error when workload set version uses package version format - #54929

Merged
marcpopMSFT merged 8 commits into
mainfrom
copilot/detect-invalid-version-format
Jul 24, 2026
Merged

Better error when workload set version uses package version format#54929
marcpopMSFT merged 8 commits into
mainfrom
copilot/detect-invalid-version-format

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Users occasionally specify a workload set version in the internal NuGet package format (e.g. 10.105.0, 11.100.0-preview.5.26309.3) instead of the user-facing format (10.0.105, 11.0.100-preview.5). Previously this produced a confusing NuGet "package not found" failure; now workload operations and global.json produce a clear error with the corrected version.

The user-facing format always has 0 as the minor component — a non-zero minor is the diagnostic signal.

Changes

  • WorkloadSetVersion.cs — adds IsWorkloadSetVersionInPackageVersionFormat(string, out string?) which detects the wrong format and computes the corrected version string (8.203.18.0.203.1, 11.100.0-preview.5.26309.311.0.100-preview.5.26309.3)
  • WorkloadSetVersion.Validation.cs — deleted; was an orphaned file with conflicting duplicate definitions not compiled into any project
  • InstallingWorkloadCommand.cs — validates both --version command-line values and workloadVersion from global.json, throwing early with a helpful message
  • CliCommandStrings.resx — adds the new workload install / global.json error strings and updates the guidance text to describe the accepted minor-component rule without contradicting valid 4-part suggestions; XLF files regenerated
  • SdkFeatureBandTests.cs — adds coverage for detecting package-format workload set versions

Error messages

'10.103.0' is not a valid workload set version. The workload set version should have '0' as the minor component (for example, '10.0.105' or '10.0.103.1'). Did you mean '10.0.103'?

'11.100.0-preview.5.26309.3' is not a valid workload set version. The workload set version should have '0' as the minor component (for example, '10.0.105' or '10.0.103.1'). Did you mean '11.0.100-preview.5.26309.3'? (Specified in 'path/to/global.json')

Copilot AI and others added 2 commits June 22, 2026 21:11
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…ment

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot AI changed the title Detect wrong workload set version format with helpful error message Better error when workload set version uses package version format Jun 22, 2026
Copilot AI requested a review from marcpopMSFT June 22, 2026 21:13
@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot Fix the build errors

/mnt/vss/_work/1/s/src/Common/WorkloadSetVersion.cs(70,34): error CS0518: Predefined type 'System.Range' is not defined or imported [/mnt/vss/_work/1/s/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/Microsoft.DotNet.MSBuildSdkResolver.csproj]
/mnt/vss/_work/1/s/src/Common/WorkloadSetVersion.cs(70,34): error CS0518: Predefined type 'System.Index' is not defined or imported [/mnt/vss/_work/1/s/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/Microsoft.DotNet.MSBuildSdkResolver.csproj]
/mnt/vss/_work/1/s/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs(8,10): error CS0246: The type or namespace name 'FactAttribute' could not be found (are you missing a using directive or an assembly reference?) [/mnt/vss/_work/1/s/test/Microsoft.DotNet.Cli.Utils.Tests/Microsoft.DotNet.Cli.Utils.Tests.csproj]
/mnt/vss/_work/1/s/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs(8,10): error CS0246: The type or namespace name 'Fact' could not be found (are you missing a using directive or an assembly reference?) [/mnt/vss/_work/1/s/test/Microsoft.DotNet.Cli.Utils.Tests/Microsoft.DotNet.Cli.Utils.Tests.csproj]

…convert xUnit tests to MSTest

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the build errors

/mnt/vss/_work/1/s/src/Common/WorkloadSetVersion.cs(70,34): error CS0518: Predefined type 'System.Range' is not defined or imported [/mnt/vss/_work/1/s/src/Resolver...

Fixed in the latest commit:

  1. WorkloadSetVersion.cs — replaced the C# range indexer [sections[0].Length..] with Substring(sections[0].Length) for net472 compatibility (both System.Range and System.Index are unavailable on full framework). Verified the Microsoft.DotNet.MSBuildSdkResolver project now builds cleanly.

  2. TransientSdkResolutionErrorDetectorTests.cs — converted from xUnit [Fact] to MSTest [TestClass]/[TestMethod] to match the project's MSTest.Sdk configuration. Verified the Microsoft.DotNet.Cli.Utils.Tests project now builds cleanly.

@marcpopMSFT
marcpopMSFT marked this pull request as ready for review July 1, 2026 23:04
Copilot AI review requested due to automatic review settings July 1, 2026 23:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves the .NET SDK workload UX by detecting when users provide a workload set version in the internal NuGet package version format (e.g. 10.105.0) and emitting an early, actionable error message with a suggested corrected user-facing version (e.g. 10.0.105) instead of failing later with a confusing “package not found”.

Changes:

  • Added WorkloadSetVersion.IsWorkloadSetVersionInPackageVersionFormat(...) to detect the internal/package-style version format and compute a corrected suggestion.
  • Validated workload set version inputs in both the workload install path (CLI / global.json) and the workload search version command validator, using new localized error strings.
  • Added unit tests for the new detection logic and migrated an MSTest project test file from xUnit [Fact] to MSTest [TestMethod].

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/Microsoft.NET.Sdk.WorkloadManifestReader.Tests/SdkFeatureBandTests.cs Adds coverage for detecting package-style workload set versions and verifying suggested corrected versions.
test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs Converts xUnit attributes to MSTest attributes to match the project’s MSTest.Sdk usage.
src/Common/WorkloadSetVersion.Validation.cs Removes an unused/orphaned duplicate validation file.
src/Common/WorkloadSetVersion.cs Introduces the new detection + suggestion helper for package-version-formatted workload set versions.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Workload/WorkloadSearchVersionsCommandDefinition.cs Updates argument validation to emit the specific “package format” error when detected.
src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx Adds a new localized string for the “workload set version in package format” error (definitions layer).
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hant.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hans.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.tr.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ru.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pt-BR.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pl.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ko.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ja.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.it.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.fr.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf Adds new trans-unit for the new error string.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf Adds new trans-unit for the new error string.
src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs Adds early validation for command-line and global.json workload set versions, throwing a helpful error with a suggested corrected version.
src/Cli/dotnet/Commands/CliCommandStrings.resx Adds new localized strings for the workload-set-version “package format” error (CLI layer), including a global.json-specific variant.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf Adds new trans-units for the new CLI-layer error strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf Adds new trans-units for the new CLI-layer error strings.
Comments suppressed due to low confidence (1)

src/Cli/dotnet/Commands/CliCommandStrings.resx:2725

  • Same issue as the non-global.json variant: the message states 'major.0.patch' but corrected workload set versions may include an additional numeric component (major.0.sdkPatch.workloadSetPatch). Consider adjusting the described format so it matches the suggestion output.
</root>

Comment thread src/Cli/dotnet/Commands/CliCommandStrings.resx Outdated
Comment thread src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx Outdated
@marcpopMSFT

Copy link
Copy Markdown
Member

Tested in codespaces for both --version and global.json.
image

image

@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot can you revert the changes to WorkloadSearchVersionsCommandDefniition.cs and the matching string changes? I believe we only care about the --version flag on workload operations or in global.json and don't care about catching this in search

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you revert the changes to WorkloadSearchVersionsCommandDefniition.cs and the matching string changes? I believe we only care about the --version flag on workload operations or in global.j...

Addressed in da7042f: reverted the workload search validation and matching command-definition resource/XLF changes. I also updated the workload install/global.json error text so it no longer contradicts valid four-part suggestions, and fixed the MSTest data-driven test that surfaced during validation.

Comment thread src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs Outdated
Comment thread src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs Outdated
Comment thread src/Common/WorkloadSetVersion.cs
- Use System.Version.TryParse instead of manual int.TryParse for
  version component parsing in IsWorkloadSetVersionInPackageVersionFormat
- Merge duplicate error strings (WorkloadSetVersionInPackageVersionFormat
  and WorkloadSetVersionInPackageVersionFormatGlobalJson) into a single
  string with an optional suffix for global.json context
- Use else if for cleaner control flow between command-line and
  global.json version checks
- Improve CS0436 pragma comment to be more specific about the cause

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@marcpopMSFT
marcpopMSFT requested a review from a team as a code owner July 23, 2026 22:14
@marcpopMSFT
marcpopMSFT requested a review from nagilson July 23, 2026 22:34
Comment thread src/Cli/dotnet/Commands/Workload/InstallingWorkloadCommand.cs Outdated
Instead of suppressing CS0436 with a pragma, remove the duplicate
Compile Include from dotnet.csproj. The class is already available
through the project reference to Microsoft.DotNet.Cli.Definitions
which has InternalsVisibleTo for dotnet.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@marcpopMSFT
marcpopMSFT merged commit ed75fed into main Jul 24, 2026
28 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/detect-invalid-version-format branch July 24, 2026 21:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants