I recently upgraded a project to .NET 6 and immediately started getting an error on your hosted build pipeline in Azure DevOps.
Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.
The solution I found was pretty simple. Before your build step in the pipeline, add a “Use .NET Core” step.
Then configure the step to use .NET 6. Depending on when you’re reading this, you may also need to check the “Include Preview Versions” option.
If you’re using YAML, the code looks like this:
steps: - task: UseDotNet@2 displayName: 'Use .NET Core sdk 6.0.x' inputs: version: 6.0.x includePreviewVersions: true