msbuild /t:metrics fails on azuredevops pipeline

Viewed 44

While running below command for the solution it works fine on command line on on-premise.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" test.sln /t:Metrics -p:Configuration=Debug -p:Platform="Any CPU"

The task used in the pipeline is :

- task: CmdLine@2
            inputs:
              script: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" Test.sln /p:AzureDevOps=true /verbosity:d /t:Metrics -p:Configuration=Debug -p:Platform="Any CPU"'
              workingDirectory: 'C:\a\1\s\Ett\Test'
              failOnStderr: true

Also tried the task :

- task: VSBuild@1
            displayName: CodeMetrics    
            inputs:
             solution: '**\CN.Test.sln'
             msbuildArgs: '/t:Metrics'      
             platform: 'Any CPU'
             configuration: 'debug'
             createLogFile: true
             logFileVerbosity: 'detailed'

However fails to run from the pipeline with below error :

The target "Metrics" does not exist in the project

2 Answers

The target 'Metrics' the nuget 'Microsoft.CodeAnalysis.Metrics' is installed in each project.

This is the key. That target won't be available until after you've restored the nuget packages. The packages will have been restored on your local machine though.

For your build pipeline to work make sure you perform a restore first, either as part of the existing invocation of MSBuild, or as a seperate step.

MSBuild /t:restore;metrics ...

Or:

Msbuild /t:restore ...
Msbuild /t:metrics ...

Based on your description and concern, in your second shared task, for msbuildArgs: '/t:Metrics' in the task, the specified target File structure '/t:Metrics' is not completed, that's why you met this issue.

To solve this issue, you could define the target to folder level where the spevified csproj file located.

For example: File structure: xx->xxx->metrics ->xx.csproj

msbuildArgs: ”/t:xx\xxx\metrics“

For more information, you could also refer to the doc: How to: Build specific targets in solutions by using MSBuild.exe .

Related