Test Task Failing in Azure DevOps - azure-devops

I have a build pipeline in Azure DevOps which has the following tasks and uses a hosted agent.
Now, when I run it the Test task fails with the following message.
Testhost process exited with error: It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
How can I install version 2.2.0 in the hosted agent?

You can add a “Use .NET Core” task and specify version of .NET Core SDK or runtime to install. Here is a sample:
- task: UseDotNet#2
displayName: 'Use .NET Core runtime 2.2.0'
inputs:
packageType: runtime
version: 2.2.0
In addition,we have deprecated .NET Core 2.2 on 19 June for Windows, Ubuntu and macOS images. This change is because 2.2 version of .NET Core has been deprecated in January, 2020. As we try only to keep the versions which are not End Of Line (2.1, 3.0 and 3.1). You can find more detailed information in this ticket: https://github.com/actions/virtual-environments/issues/975 .

Related

dotnet workload restore for MAUI fails with .NET 7

Fails to install workloads for MAUI for .NET 7 when running in azure dev ops. I was running the same pipeline in .NET 6 and it worked fine, but when I updated to .NET 7, it started failing to install the MAUI workload.
YAML
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 7.x'
inputs:
version: 7.x
- task: DotNetCoreCLI#2
displayName: 'dotnet workload'
inputs:
command: custom
custom: 'workload '
arguments: 'install maui'
Logs
Installing pack Microsoft.Maui.Core.Ref.android version 7.0.0-rc.1.6430...
Workload installation failed. Rolling back installed packs...
Rolling back pack Microsoft.Maui.Core.Ref.android installation...
Workload installation failed: Unable to load the service index for source https://nuget.telerik.com/v3/index.json.
##[debug]Exit code 1 received from tool 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[debug]STDIO streams have closed for tool 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
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://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[debug]task result: Failed
##[error]Dotnet command failed with non-zero exit code on the following projects :
##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects :
##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects :
Finishing: dotnet workload
Comments
It is strange that is trying to install the MAUI workload 7.0.0-rc.1.6430 even though I am using the latest .NET 7 and not the release candidate.
This exact pipeline was working with .NET 6
I was able to fix this by specifying the --source on the command. I think me having external nuget sources for private feeds was interfering with it selecting the correct workload version somehow.
- task: DotNetCoreCLI#2
displayName: 'dotnet workload'
inputs:
command: custom
custom: 'workload '
arguments: 'install maui --source https://api.nuget.org/v3/index.json'
Installing pack Microsoft.Maui.Core.Ref.android version 7.0.0-rc.1.6430..
When you run the dotnet workload install maui, it will install maui according to the .net SDK version specified in global.json file firstly.
When you have a global.json file in your project, it will keep the version specified in the file even if you install the latest .NET 7 in the Pipeline.
To solve this issue, you can modify the global.json file and define the .net version(7.0.100).
For example:
{
"sdk": {
"allowPrerelease": true,
"rollForward": "disable",
"version": "7.0.100"
}
}
You can disable the rollForward in global.json file. Then it will not automatically upgrade the dotnet version of the project.
When you run the pipeline with the global.json above, it will use the version: Microsoft.Maui.Core.Ref.android version 7.0.49. This is the latest version of Maui.
Result:

Azure DevOps Pipelene doesn't compile .netstandard 2.0 projects

I'm stuck in a rut with this proble. After converting some solution projects in .netstandard 2.0 the pipeline doesn't compile. Other are .NET Framework 4.8 projects.
Here the errors
Installed SDKs: No .NET SDKs were found.
Install the [6.0.400] .NET SDK or update
[E:\myApplicationFolder\global.json] to match an installed SDK.
Download a .NET SDK: https://aka.ms/dotnet-download
I tried the following steps:
installed VS 2022 and tells to the pipeline to use VS 2022 msbuild
installed the .NET sdk
created the global.json choerent with the solution
checked the environment variables (they point to C:\Program Files\dotnet)
checked the version of .NET SDK
This is the global.json
{
"sdk": {
"version": "6.0.400"
}
}
There are the configuration on the pipeline
I don't have any troubles building the solution with msbuild from powershell.
Any other suggestions? Thanks
Many problems, Azure DevOps isn't updated to the latest version and can't manage .NET 6.0 solutions. I had to specify the msbuild of VS 2022 also to restore nuget packages

Azure Devops - Compatibility problems moving from .NET Core 3.1 to .NET 5 at Nuget Package

I have a .NET Core solution which was running well using .NET Core 3.1 using a Pipeline on Azure Devops. Everything was working fine on the Pipeline.
After moving from .NET Core 3.1 to .NET 5.0, I started to have some strange troubles running the pipeline, specifically with Nuget packages.
I can build with no problems, but when it starts to pack using Nuget Package, I've got this error:
[error] The nuget command failed with exit code(1)
NU1202: Package Microsoft.EntityFrameworkCore 5.0.0 is not compatible with net50 (.NETFramework,Version=v5.0). Package Microsoft.EntityFrameworkCore 5.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1)
Some weird fact is that this solution is running fine at the local machine.
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.8.8.9</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
I already tried to change the OS on the Build, but I've got this error:
The current available version of MSBuild is 16.7.0.37604. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
Does someone have an idea?
Package Microsoft.EntityFrameworkCore.Relational 5.0.0 supports:
netstandard2.1 (.NETStandard,Version=v2.1)
This is because it was using an old version of Nuget. You can try to change it to 5.x and restore.
Here is a case with similar issue you can refer to.

Does Azure Pipeline Support .NET Core 3.1.7?

This is the error I get:
This is my configuration:
Can anyone help me?
I fix that for the latest .NET release.
The issue can be fixed with this line of code in your pipeline (.yaml) file.
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 6.0.x'
inputs:
version: 6.x
includePreviewVersions: true
Just add the above step to your YAML file.
When you set the .NET Core SDK version to 3.x, it automatically download and install the latest in major version SDK 3.1.401, but SDK 3.1.401 is included in
Visual Studio 16.7.1. Since the hosted agent installed Visual Studio 16.6.30320.27, which doesn't include SDK 3.1.401, you would get the error during the build.
Currently, you could set the .NET Core SDK version to 3.1.302, or 3.1.107, which should solve your issue.
https://dotnet.microsoft.com/download/dotnet-core/3.1
This issue has been reported to product team in the following case, you can follow the case to track the status:
https://developercommunity.visualstudio.com/content/problem/1145815/net-coremsbuild-tooling-not-finding-right-version.html

Failed to download or parse release-index.json with error:

My Azure Devops build has started failing with the following message in the log
Starting: Use .NET Core sdk
==============================================================================
Task : Use .NET Core
Description : Acquires a specific version of the .NET Core SDK from the internet or the local cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks. Additionally provides proxy support.
Version : 2.165.0
Author : Microsoft Corporation
Help : https://aka.ms/AA4xgy0
==============================================================================
Tool to install: .NET Core sdk version 3.x.
##[error]Failed to download or parse release-index.json with error: {}
Finishing: Use .NET Core sdk
The YAML contains
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk'
inputs:
packageType: 'sdk'
version: 3.x
the image is windows-2019
I ran the pipeline again some time later and it worked.
I had enabled diagnostics. Not sure if that helped.