Azure DevOps - The Feature 'Global Using Directive' is currently in Preview

Created on

Solution to resolving this error: 'Error CS8652: The feature 'global using directive' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.'


Azure Devops Issue When Using .NET 6.0 and C# 10

I upgraded my ASP.NET Core web application from .NET Core 3.1 (C# 9.0) to .NET 6.0 (C# 10).

Read About .NET Versions and the Corresponding C# Language Versions via Microsoft's Documentation

This was causing my Azure DevOps pipeline to fail the build step with the following error:

Error CS8652: The feature 'global using directive' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

Solution to The 'Unsupported' Error in the Pipeline

In order to get the Pipeline to build our solution with C# 10, we have to explicitly tell the pipeline to run in a Windows 2022 environment that will use Visual Studio 2022.

At the time of writing this, vmImage: 'windows-latest' does not default to windows-2022, so we update our vmImage like this:

pool:
  vmImage: 'windows-2022'

Now the Pipeline will be able to build your .NET 6 application in DevOps!

Additionally, This is a fully working Azure DevOps pipeline for a .NET 6.0 project using C# 10.0:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

# Add this Command to Include the .NET 6 SDK
- task: UseDotNet@2
  displayName: Use .NET 6.0
  inputs:
    packageType: 'sdk'
    version: '6.0.x'

# Add a Command To List the Current .NET SDKs (Sanity Check)
- task: CmdLine@2
  inputs:
    script: 'dotnet --list-sdks'

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Azure Devops - The current .NET SDK does not support targeting .NET 6.0

Other References

GitHub - Issue