NJS
NJS

Reputation: 506

How to find the C# version of my Azure build agent

I can build my code locally but the code will not build in my Azure pipeline. The build error message suggests my Azure build agent is using a different version of C#. How do I check to see what version it's using?

Upvotes: 4

Views: 2819

Answers (3)

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

In the log of visual studio build task, you can search csc.exe, then you could find the path of csc.exe. Then you could check language version by calling csc.exe -langversion:?

VS2019 : C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn

Regarding specify the hosted agent dynamic, you could use parameters in YAML pipeline, then you could choose the image in Run pipeline form:

For example:

parameters:
- name: image
  displayName: Pool Image
  type: string
  default: windows-latest
  values:
  - windows-latest
  - vs2017-win2016
  - ubuntu-latest
  - ubuntu-16.04
  - macOS-latest
  - macOS-10.14

trigger:
- none


jobs:
- job: myjob
  pool: 
    vmImage: ${{ parameters.image }}
  steps:
    - task: CmdLine@2
      inputs:
        script: '.\csc.exe -langversion:?'
        workingDirectory: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn'

Upvotes: 3

Hugh Lin
Hugh Lin

Reputation: 19391

C# language version is determined by its target framework and Visual Studio version:

For every release prior to Visual Studio 2019, the default C# language version was always equivalent to Latest Major. In Visual Studio 2017, C# evolved and released three minor versions: 7.1, 7.2, and 7.3. However, new projects were still defaulting to C# 7.0. This proved frustrating for C# developers who wanted to use new features, but had to manually change the language version for each new project.

To address this problem, the default C# language version is determined by its target framework:

  • If you are targeting .NET Core 3.0 preview, the C# language version will be C# 8.0 Preview.
  • If you are targeting .NET Framework or any non-preview of .NET Core, the C# language version will by C# 7.3.

If you specify a language version via LangVersion in a project or props file, that language version overrides the previously described default.

For details ,please refer to this document.

So you need to check your specified agent, target framework and the value of <LangVersion> xx </ LangVersion> in the project file to determine c# version.

As a workaround ,you can try to add /property:langversion=latest in MsBuild Argument of the Visual Studio Build task. Or since you can build your code locally, you can use a private agent to build using the local environment.

Upvotes: 0

Much to learn
Much to learn

Reputation: 56

To check installed software on your build agent from azure devops go to:

Settings > Agent pools > buid-agents > build-agent-0-1

and go to Capabilities tab

Upvotes: 2

Related Questions