diff --git a/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommand.cs b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommand.cs index 15049f909b09..ceff25cd8884 100644 --- a/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommand.cs +++ b/src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallCommand.cs @@ -155,7 +155,9 @@ public override int Execute() throw new GracefulException(string.Format(CliCommandStrings.CannotCombineSkipManifestAndRollback, WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, InstallingWorkloadCommandParser.FromRollbackFileOption.Name), isUserError: true); } - else if (_skipManifestUpdate && SpecifiedWorkloadSetVersionOnCommandLine) + else if (_skipManifestUpdate && SpecifiedWorkloadSetVersionOnCommandLine && + !IsRunningRestore) // When running restore, we first update workloads, then query the projects to figure out what workloads should be installed, then run the install command. + // When we run the install command we set skipManifestUpdate to true as an optimization to avoid trying to update twice { throw new GracefulException(string.Format(CliCommandStrings.CannotCombineSkipManifestAndVersion, WorkloadInstallCommandParser.SkipManifestUpdateOption.Name, InstallingWorkloadCommandParser.VersionOption.Name), isUserError: true); diff --git a/test/dotnet.Tests/CommandTests/Workload/Restore/GivenDotnetWorkloadRestore.cs b/test/dotnet.Tests/CommandTests/Workload/Restore/GivenDotnetWorkloadRestore.cs index 301293b0141f..d36199b3df81 100644 --- a/test/dotnet.Tests/CommandTests/Workload/Restore/GivenDotnetWorkloadRestore.cs +++ b/test/dotnet.Tests/CommandTests/Workload/Restore/GivenDotnetWorkloadRestore.cs @@ -15,7 +15,7 @@ public GivenDotnetWorkloadRestore(ITestOutputHelper log) : base(log) [Fact] public void ProjectsThatDoNotSupportWorkloadsAreNotInspected() { - if(IsRunningInContainer()) + if (IsRunningInContainer()) { // Skipping test in a Helix container environment due to read-only DOTNET_ROOT, which causes workload restore to fail when writing workload metadata. return; @@ -38,7 +38,7 @@ public void ProjectsThatDoNotSupportWorkloadsAreNotInspected() [Fact] public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBreakTheBuild() { - if(IsRunningInContainer()) + if (IsRunningInContainer()) { // Skipping test in a Helix container environment due to read-only DOTNET_ROOT, which causes workload restore to fail when writing workload metadata. return; @@ -58,6 +58,31 @@ public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBr .Pass(); } + [Fact] + public void VersionOptionShouldNotConflictWithSkipManifestUpdate() + { + if (IsRunningInContainer()) + { + // Skipping test in a Helix container environment due to read-only DOTNET_ROOT, which causes workload restore to fail when writing workload metadata. + return; + } + + var projectPath = + _testAssetsManager + .CopyTestAsset(TransitiveReferenceNoWorkloadsAssetName) + .WithSource() + .Path; + + var result = new DotnetWorkloadCommand(Log, "restore", "--version", "9.0.100") + .WithWorkingDirectory(projectPath) + .Execute(); + + // Should not fail with "Cannot use the --skip-manifest-update and --sdk-version options together" + // The command may fail for other reasons (e.g., version not found), but it should not fail with the skip-manifest-update error + result.StdErr.Should().NotContain("Cannot use the"); + result.StdErr.Should().NotContain("--skip-manifest-update"); + } + private bool IsRunningInContainer() { if (!File.Exists("/.dockerenv"))