Azure DevOps Pipeline PostSharp failure on linux VM - azure-devops

I had planned to move my DevOps Pipeline to linux vm. Unfortunately, I faced with this problem. I am using Postsharp 6 on my .Net Core 2.2 project.
Build FAILED.
/home/vsts/.nuget/packages/postsharp/6.1.18/build/PostSharp.targets(148,5): error MSB4062: The "PostSharp.MSBuild.PostSharpValidateLanguageVersion" task could not be loaded from the assembly /home/vsts/.nuget/packages/postsharp/6.1.18/build//net471/PostSharp.MSBuild.v6.1.18.Release.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. [/home/vsts/work/1/s/Core.csproj]
/home/vsts/.nuget/packages/postsharp/6.1.18/build/PostSharp.targets(148,5): error MSB4062: Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [/home/vsts/work/1/s/Core.csproj]
0 Warning(s)
1 Error(s)

PostSharp doesn't work on Linux VM.
The only solution is using Windows Server on yaml. Even Selenium removed Postharp support.
trigger:
- master
pool:
vmImage: 'windows-2019'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
You can look at the pictures to understand the steps better.
Update
PostSharp 6.3.5 preview version supports Linux and macOS builds.
Also, you can create a docker image too. I am using these images:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build

Related

Azure CI Pipeline - DotNetCoreCLI#2 Task error

I developed WebAPI project using .NET Core 3.1.0 and integration tests using XUnit.
I added the below task in Azure DevOps CI Pipeline (azure-pipelines.yaml) to run the integration tests project.
- task: DotNetCoreCLI#2
displayName: 'Run API integration tests - $(buildConfiguration)'
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration)'
publishTestResults: true
projects: '**/IntegrationTests/IntegrationTests.csproj'
I got the below error during pipeline execution. How to resolve this error?
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : /home/vsts/work/1/s/src/IntegrationTests/IntegrationTests.csproj
I've had a smiller issue but with .netcore 2.2. The problem was that the test tries to build before the test starts restoring the packages for the test, thus fails before the test runs or builds. One thinge that help me overcome this problem was this FAQ:
Most dotnet commands, including build, publish, and test include an implicit restore step. This will fail against authenticated feeds, even if you ran a successful dotnet restore in an earlier step, because the earlier step will have cleaned up the credentials it used.
To fix this issue, add the --no-restore flag to the Arguments textbox.
I've also read that the DotNetCLI had some issues when it came to tests like this one here
So I ended up using a script to solve this and other issues related to package restore.
- script: dotnet test '**/IntegrationTests/IntegrationTests.csproj' --configuration $(buildConfiguration) --logger trx;LogFileName=C:\temp\results
displayName: 'Run API integration tests - $(buildConfiguration)'
I hope that will help you or anyone who has similar issues.
I've had exactly the same problem, with the difference that my solution consisted of .net5 apps as well as .netcore3.1 apps.
I was able to solve this problem by specifying the newer dotnet runtime in the azure pipeline:
- task: UseDotNet#2
inputs:
version: '5.0.x'
packageType: runtime

Azure Devops Build failing for .Net 5 when using multiple frameworks

I have a project that builds using the following frameworks:
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
This compiles just fine on my local machine, but when I push it to Azure, it fails.
When I have the following in my YAML file:
variables:
solution: '**/*.sln'
buildConfiguration: 'Release'
buildPlatform: 'Any CPU'
platform: x64
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
Then I get:
##[error]C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5):
Error MSB3644: The reference assemblies for .NETFramework,Version=v5.0
were not found. To resolve this, install the Developer Pack
(SDK/Targeting Pack) for this framework version or retarget your
application. You can download .NET Framework Developer Packs at
https://aka.ms/msbuild/developerpacks
And if I try
- task: VSBuild#1
displayName: 'Build all'
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
maximumCpuCount: true
I get:
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,5):
Error MSB3644: The reference assemblies for .NETFramework,Version=v5.0
were not found. To resolve this, install the Developer Pack
(SDK/Targeting Pack) for this framework version or retarget your
application. You can download .NET Framework Developer Packs at
https://aka.ms/msbuild/developerpacks
The developer packs documentation refer only to the older .Net Framework, so I suspect this is irrelevant/outdated.
This works fine if I change .Net 5 for .Net Core 3.1, i.e. <TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
The reason your project doesn't build successfully is because the Microsoft-Hosted agent doesn't have the.NET 5.0 SDK installed.
You can download the.NET 5.0 SDK using Use.NET Core Task:
- task: UseDotNet#2
inputs:
packageType: 'sdk'
Version: '{version}'
includePreviewVersions: {true/false}
This task can download a specific version of the .Net SDK from the network and add it to the PATH.
In addition, since you are using multiple versions of .NET in your project, you can use this task to specify which version of.NET you will use in the following tasks.
In other words, this task has two functions:
Download a specific SDK version that is not installed.
Specify which SDK version will be used for the following tasks.
I think there is a problem with build agent machines.
If you use cloud azure devops you need to wait when they will update their build machines.
If you use on premise azure devops try to update build machines by yourself.

Run Google Test with build pipeline in Azure DevOps

I have problems to get my gtest runing in my build pipeline. My solution works well to build and run test case in Visual Studio 2017. On the DevOps environment I use .Net Desktop setup with minor modification. The build task work fine as well in pipeline.
I try use default VSTest task, but I'm not sure it right task for run Google Test that is create with Visual Studio project from VS IDE.
Build pipline yml script
# .NET Desktop
trigger:
- master
# Install build environment
pool:
vmImage: 'windows-latest'
name: Hosted VS2017
variables:
solution: '**/*.sln'
buildPlatform: 'x86'
buildConfiguration: 'Debug'
steps:
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
# Build VS solutions including gtest project.
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Run gTest, this task not working see log below.
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
VSTest log output
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : d:\a\1\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio build tools installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio installation with version [15.0,16.0).
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.
Yes, VSTest task which will use VSTest.Console.exe. It's able to run custom test adapters (like the Google Test Adapter).
However, after go through the build-in Included Software of Hosted VS2017 build agent, it's not listed. If so, you could use Self-hosted Windows agents.
You can download the Google Test Adapter as Visual Studio Extension, unzip it (rename .vsix file to .zip) and place that entire unzipped folder somewhere on your Build agent machine. The build step then has to point to that directory.
Additionally of course, your project should include the "googletest" NuGet package in order to run the tests.
If you still not able to get it work, please remote to build agent machine and manually run the build and test use visual studio or command line instead through Azure DevOps pipeline. This will narrow down if it's an environment issue.

NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio

I am trying to build a repository in Azure Pipelines. It builds OK in Visual Studio, but when using Azure Pipelines (with an agent running on a build machine), it fails with the following error:
The nuget command failed with exit code(1) and error
Project MyProject is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2).
Project MyProject supports: netstandard2.0 (.NETStandard,Version=v2.0)
How can I fix this?
And here is the yaml build script:
pool:
name: MyBuildServer
demands:
- msbuild
- visualstudio
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore'
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
- task: VSTest#2
displayName: 'Run tests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio
It seems that the version of nuget used on the Azure pipeline is not the latest version, which may cause the incompatibility issues.
To resolve this issue, you can try to add a NuGet Tool Installer task point it to a Version of NuGet.exe to install, which you simply specify the version number of the desired NuGet.exe you want to execute in the build.
Once this have been properly configured, the builds all succeeded using the latest incarnation of .net core.
Besides, if above not resolve your question, you can try to use the dotnet restore task instead of nuget restore task.
Hope this helps.

Not Loading Indexed Sources for nuget packages from Azure Devpos during debugging

Trying to use azure yml for build pipleline to publish symbols to allow nuget pkg to be debuggable usin azure devops. I see PDB files are donwloaded to the symbols cache folder but stepping thru is asking for source file location in visual studio, even when i have indexed the source code during publish symbol.
I have tried to enable different options in visual studio debugging but nothing seems to help
Here is my yml
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r) # need this for byBuildNumber verisonScheme nuget pack
# the build will trigger on any changes to the master branch
trigger:
- master
# the build will run on a Microsoft hosted agent, using the lastest Windows VM Image
pool:
vmImage: 'windows-latest'
# these variables are available throughout the build file
# just the build configuration is defined, in this case we are building Release packages
variables:
buildConfiguration: 'Release'
#The build has 3 seperate tasks run under 1 step
steps:
# The first task is the dotnet command build, pointing to our csproj file
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: 'src/Common.Core/Common.Core.csproj'
- task: PublishSymbols#2
inputs:
symbolsFolder: '$(Build.SourcesDirectory)'
searchPattern: '**/bin/**/*.pdb'
indexSources: true
publishSymbols: true
symbolServerType: 'teamServices'
treatNotIndexedAsWarning: true
symbolsProduct: '$(Build.DefinitionName)'
symbolsVersion: '$(Build.BuildNumber)'
symbolsArtifactName: '$(name).Symbols_$(BuildConfiguration)'
# The second task is dotnet pack command again pointing to the csproj file
# The nobuild means the project will not be compiled before running pack, because its already built in above step
- task: DotNetCoreCLI#2
displayName: "dotnet pack"
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: 'src/Common.Core/Common.Core.csproj'
nobuild: true
includeSymbols: true
versioningScheme: 'byBuildNumber'
# The last task is a nuget command, nuget push
# This will push any .nupkg files to the 'Nuget' artifact feed
# allowPackageConflicts allows us to build the same version and not throw an error when trying to push
# instead it just ingores the latest package unless the version changes
- task: NuGetCommand#2
displayName: 'nuget push'
inputs:
command: 'push'
feedsToUse: 'select'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'myNuget'
allowPackageConflicts: true
I would expect that when i am debugging nuget packages with symbols enabled with idnexed soruce code, it automatically downloads the pdf file and the source code.
Visual Studio Settings for debugger
I see PDB files are donwloaded to the symbols cache folder but
stepping thru is asking for source file location in visual studio,
even when i have indexed the source code during publish symbol.
You should let the debugger know where to find your source files. First, please rename your xx.nupkg to xx.zip and check if it contains necessary source files.
After that you can right-click Solution in Solution Explorer=>Properties=>Debug Source Files,click the New Line option to add the path of your nuget source files to the debug source files setting.
I would expect that when i am debugging nuget packages with symbols
enabled with idnexed soruce code, it automatically downloads the pdf
file and the source code.
Maybe you can get some help from this issue. You can try setting the build action of the source files as C# compiler when you create the nuget package for .net core.