Pack Failed: error NETSDK1194: Issue running dotnet publish with --output property set

Error Message:
error NETSDK1194: The “–output” option isn’t supported when building a solution.

  10:42:28 [INF] > /usr/bin/dotnet pack /home/runner/work/vc-module-task-management/vc-module-task-management/VirtoCommerce.TaskManagement.sln --configuration Release --include-symbols --no-build --output /home/runner/work/vc-module-task-management/vc-module-task-management/artifacts /property:SymbolPackageFormat=snupkg /property:Version=3.206.0
  10:42:28 [DBG] MSBuild version 17.5.0-preview-23061-01+040e2a90e for .NET
  Error: /usr/share/dotnet/sdk/7.0.200/Current/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets(36,5): error NETSDK1194: The "--output" option isn't supported when building a solution. [/home/runner/work/vc-module-task-management/vc-module-task-management/VirtoCommerce.TaskManagement.sln]
  10:42:29 [ERR] /usr/share/dotnet/sdk/7.0.200/Current/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets(36,5): error NETSDK1194: The "--output" option isn't supported when building a solution. [/home/runner/work/vc-module-task-management/vc-module-task-management/VirtoCommerce.TaskManagement.sln]
  Error: Target "Pack" failed
  10:42:29 [ERR] Target Pack failed
  Nuke.Common.Tooling.ProcessException: Process 'dotnet' exited with code 1.
     > /usr/bin/dotnet pack /home/runner/work/vc-module-task-management/vc-module-task-management/VirtoCommerce.TaskManagement.sln --configuration Release --include-symbols --no-build --output /home/runner/work/vc-module-task-management/vc-module-task-management/artifacts /property:SymbolPackageFormat=snupkg /property:Version=3.206.0
     @ /home/runner/work/vc-module-task-management/vc-module-task-management
  
     at Nuke.Common.Tooling.ProcessExtensions.AssertZeroExitCode(IProcess process)
     at Nuke.Common.Tools.DotNet.DotNetTasks.DotNetPack(DotNetPackSettings toolSettings)
     at VirtoCommerce.Build.Build.<get_Pack>b__223_1() in /home/runner/work/vc-build/vc-build/src/VirtoCommerce.Build/Build.cs:line 252
     at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)
     at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)
     at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)
Warnings & Errors
  [ERR] Pack: /usr/share/dotnet/sdk/7.0.200/Current/SolutionFile/ImportAfter/Microsoft.NET.Sdk.Solution.targets(36,5): error NETSDK1194: The "--output" option isn't supported when building a solution. [/home/runner/work/vc-module-task-management/vc-module-task-management/VirtoCommerce.TaskManagement.sln]
  [ERR] Pack: Target Pack failed

The key reason of the error in SDK 6.0.406 and MSBuild version 17.5.0-preview-23061-01+040e2a90e for .NET. You can find more details here: Issue running dotnet publish with --output property set · Issue #8194 · dotnet/core (github.com)

To resolve the issue please use custom command and install
.NET 6.0.309

On GitHub workflow, you need to Setup .NET SDK

steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
  with:
    dotnet-version: '6.0.309'

On Azure DevOps you can add task to CI job steps:

  - task: UseDotNet@2
    inputs:
      version: '6.0.309'
      packageType: sdk

Copy from error NETSDK1194: The “–output” option isn’t supported when building a solution. (steven-giesel.com)

Fix 1: Use an older SDK version

The simplest fix would be to use an older SDK version:

      - name: Set up .NET
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '7.0.103'

Here the issue should not pop up - but that also doesn’t work all the time. I did have this issue even with projects that target .NET 6 and .NET 6 only. So that doesn’t guarantee a working build pipeline.

So even if you’re using .NET do the following to get back one release version

      - name: Set up .NET
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '6.0.405'

Fix 2: Use --output on project level, not on the solution level

If you are suffering from that problem you might want to solve the issue and set --output switch on a project level. That can significantly increase your build time.

Fix 3: Use the correct toggle for the appropriate task

I will quote here a response from @baronfel

… a) We’ll downgrade the error to a warning - we think this usage pattern is harmful and can lead to builds that are harder to debug, especially when projects are multi-targeted or have differing sets of PackageReference versions.

  1. We’ll skip the logic for the pack command entirely - pack has stable and correct semantics when the -o flag is specified (because it sets PackageOutputPath instead of OutputPath directly)

Taken from here

With the following toggles to be used (instead of --output):

Command Property Example
build OutputPath dotnet build --property:OutputPath=DESIRED_PATH
clean OutputPath dotnet clean --property:OutputPath=DESIRED_PATH
pack PackageOutputPath dotnet pack --property:PackageOutputPath=DESIRED_PATH
publish PublishDir dotnet publish --property:PublishDir=DESIRED_PATH
store OutputPath dotnet store --property:OutputPath=DESIRED_PATH
test TestResultsDirectory dotnet test --property:OutputPath=DESIRED_PATH

This should fix your build pipeline in an instant.

Hotfix for Virto Commerce CLI (VC-BUILD) is awailable in Release 3.13.0-alpha.126 · VirtoCommerce/vc-build (github.com).

We choose to use the correct toggle for the appropriate task.