Better error when workload set version uses package version format - #54929
Conversation
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…ment Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
|
@copilot Fix the build errors |
…convert xUnit tests to MSTest Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Fixed in the latest commit:
|
There was a problem hiding this comment.
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 theworkload search versioncommand 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>
|
@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>
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. |
- 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>
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>


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 andglobal.jsonproduce a clear error with the corrected version.The user-facing format always has
0as the minor component — a non-zero minor is the diagnostic signal.Changes
WorkloadSetVersion.cs— addsIsWorkloadSetVersionInPackageVersionFormat(string, out string?)which detects the wrong format and computes the corrected version string (8.203.1→8.0.203.1,11.100.0-preview.5.26309.3→11.0.100-preview.5.26309.3)WorkloadSetVersion.Validation.cs— deleted; was an orphaned file with conflicting duplicate definitions not compiled into any projectInstallingWorkloadCommand.cs— validates both--versioncommand-line values andworkloadVersionfromglobal.json, throwing early with a helpful messageCliCommandStrings.resx— adds the new workload install /global.jsonerror strings and updates the guidance text to describe the accepted minor-component rule without contradicting valid 4-part suggestions; XLF files regeneratedSdkFeatureBandTests.cs— adds coverage for detecting package-format workload set versionsError messages