How do I get Azure DevOps to build a .NET 4.8 app? - asp.net

When we run dotnet build on a .net 4.8 app, we get an error message. I attempted to install the developer pack for 4.8. However, that fails and I think the reason it fails is that .NET 4.8 is already installed on the system. What's the right way to resolve this issue?
##[error]C:\Program Files\dotnet\sdk\6.0.300\Microsoft.Common.CurrentVersion.targets(1221,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v4.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
Is it that we cannot use dotnet build for 4.8 apps? Do we need to use MSBuild instead?

It requires the build agent be windows based, e.g. vmImage: 'windows-2022'.
- task: VSBuild#1
displayName: 'Dotnet build'
inputs:
solution: '*.sln'
msbuildArgs: '/t:build /p:DeployOnBuild=true /p:OutputPath="$(Build.ArtifactStagingDirectory)"'
restoreNugetPackages: true
configuration: '$(buildConfiguration)'
The above assumes the solution file is located in the root of the source repository.
While restoreNugetPackages is optional I received package not found errors until enabling it.

Related

.NET Core 3.1 application not building on Azure pipeline anymore (.NET 5)

Until recently our .Net Core 3.1 applications were building and publishing fine on Azure pipelines. But over the last couple of days the build pipelines have started to fail with the error:
##[error]C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5):
Error NETSDK1005: Assets file 'D:\a\1\s\ProjectFolder\src\Project\obj\project.assets.json' doesn't have a target for 'netcoreapp3.1'.
Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project.
(ResolvePackageAssets target) ->
C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1005: Assets file 'D:\a\1\s\ProjectFolder\src\Project\obj\project.assets.json' doesn't have a target for 'netcoreapp3.1'.
Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. [D:\a\1\s\ProjectFolder\src\Project\Project.csproj]
The build pipeline is setup as follows for the solution build step that is failing.
Any ideas how to resolve this with the least amount of change?
.NET Core 3.1 application not building on Azure pipeline anymore (.NET 5)
Please try to update the nuget.exe to the 5.8.0 by the task NuGet tool installer:
You could check this thread for some more details.
had the same problem with a local build agent
error NETSDK1005: Assets file 'project.assets.json' ....
Update NuGet.exe to the 5.8.0 version or above
and clearing NuGet cache:
dotnet nuget locals all --clear
Download Nuget
found here

Azure DevOps pipeline fails at Restore - Test project is not compatible with netcoreapp2.2 Project supports: netcoreapp3.0

I have a solution with 2 projects:
Client Library project made for .NET Standard 2.0
Test project for .NET Core 3.0
And I created Azure DevOps pipeline which builds and packs this library for DevOps private Nuget feed.
The pipeline contains the following steps:
Use NuGet >= 5.3.1 (added this hoping to solve the issue)
Use .Net Core sdk 3.0.100 (added this hoping to solve the issue)
Restore packages
Build
...
But the process fails at Restore packages step with:
error NU1201: Project [Test Project] is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Project [Test Project] supports: netcoreapp3.0 (.NETCoreApp,Version=v3.0)
So how can I set up CI/CD for .Net Core 3.0?
I DO NOT use YAML - I hate that thing.
I tried "Use Nuget" to force the pipeline to use the latest Nuget.
I also tried to for it using the latest .Net Core 3.1.x.
All this doesn't help.
What helped was the re-creation of the test project. Now the pipeline works!

Specify MSBuild Version in DotNetCoreCLI Task in Azure Pipeline

I am using a DotNetCoreCLI task to build a project. But I would like to build it with MSBuild 16.0 what seems to be not possible so far. Here are the facts (snippet from Azure Pipelines Yaml):
pool:
vmImage: 'windows-2019'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
projects: '$(BuildProjectFilter)'
arguments: '--configuration $(BuildConfiguration) -:Platform=$(BuildPlatform) -p:VisualStudioVersion=16.0 -p:tv=16.0'
No matter what I try the dotnet build command always uses ToolsVersion 15.0:
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.156.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\src\xxx.csproj --configuration release -p:Platform=x64 -p:VisualStudioVersion=16.0 -p:tv=16.0
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
If I only supply the -tv:16.0 switch MSBuild complains:
MSBUILD : error MSB1040: ToolsVersion is not valid. The tools version "16.0" is unrecognized. Available tools versions are "15.0".
If I supply -p:VisualStudioVersion=16.0 -p:tv=16.0 in combination the Error is recognized later by Fody telling me
Fody is only supported on MSBuild 16 and above. Current version: 15.
Of course, downgrading Fody might be a solution. But I would prefer to use MSBuild 16 as it should be available in this vm image. Is there a way to achieve that?
I think you'd better specified the higher version of .NET core SDk 2.2.401 in your task.
If I use SDK 2.2.101 to build project, I will receive the same error message with you:
To explain this, you can see the below content which mentioned in the doc:
If the .Net Core SDK version you used is lower than 2.2.401, since these lower version SDK could not be compatible with VS2019. At this time, even you specified VS 2019, it will still use the build engine which belong to VS2017. That's why in your first error log, the build engine this pipeline used is 15.9.20+g88f5fadfbe
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
As test, after I build project with the .Net Core SDK which version is 2.2.401, as the below pic you see:
The MSbuild version it took is 16. So, it satisfied the definition of the underlying fody file:
This is part of the underlying fody file. You can see, it is defined as only your MSbuild version is 16, or it will throw the error message like you received.
So, to solve your issue, I recommend you try with specifying the .Net Core SDK as 2.2.401 or above version in the task.

Building Multiple Solutions Targeting Different .Net Core Version In Travis

I have two .Net Core solutions in my repository, one targeting .Net Core 2.2 and the other .Net Core 3.
I want Travis to build both of these Solutions, but I can only specify one version in the .travis.yml, Thus the the other project fails to build.
My .travis.yml:
dist: xenial
language: csharp
mono: none
dotnet: 2.2
script:
#Build Major Application
- dotnet restore NetCore22Solution/NetCore22Solution.sln
- dotnet build NetCore22Solution/NetCore22Solution.sln
#Build Services
- dotnet restore NetCore3Solution/NetCore3Solution.sln
- dotnet build NetCore3Solution/NetCore3Solution.sln
How do I specify I also need .Net Core 3?
I searched travis's c# forum, github issues and obviously google, but didn't find any solution.
I tried adding the required version as a package and it worked:
addons:
apt:
packages:
- dotnet-sdk-3.0
Travis honestly downloaded and installed SDK.

DevOps hosted pipeline fail to build .NET Core 2.2

With the release of .NET Core 2.2 I expected to be able to build such projects in our Microsoft-hosted DevOps (Azure) pipeline. But the restore step fails, saying 2.2 is not supported:
2018-12-11T14:57:49.0856135Z "D:\a\1\s\My.Project\My.Project.csproj" (Restore target) (1) ->
2018-12-11T14:57:49.0857867Z "D:\a\1\s\MyProject.EntityFramework\MyProject.EntityFramework.csproj" (_GenerateRestoreGraphProjectEntry target) (2:3) ->
2018-12-11T14:57:49.0858029Z (_CheckForUnsupportedNETCoreVersion target) ->
2018-12-11T14:57:49.0858191Z C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2. [D:\a\1\s\MyProject.EntityFramework\MyProject.EntityFramework.csproj]
2018-12-11T14:57:49.0858287Z
2018-12-11T14:57:49.0858338Z
2018-12-11T14:57:49.0858398Z "D:\a\1\s\My.Project\My.Project.csproj" (Restore target) (1) ->
2018-12-11T14:57:49.0858504Z "D:\a\1\s\My.Project\My.Project.csproj" (_GenerateRestoreGraphProjectEntry target) (1:5) ->
2018-12-11T14:57:49.0858645Z C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2. [D:\a\1\s\My.Project\My.Project.csproj]
The project builds fine locally, so I think it is most likely that I'm missing something - especially as I come up with nothing on my internet search for similar errors.
Could it really be it is not supported yet?
OK, so there is a task ".NET Core Installer" that can be added before the Restore task, and by requesting 2.2.100 to be installed first of all the build passes.
This does trick to my project:
steps:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core SDK Tool Installer'
inputs:
version: 2.2.100
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
I had the same problem with my pipeline. Here is the solution:
Add to your job (press plus button) in the pipeline task .NET Core SDK Installer. You can search for it in a search box
Make sure to put that task on the top of your job. You can use drag&drop.
Set up version of .Net Core SDK Installer at least the same your version.
You can see all available version by pressing on the "here" word the in the popup
The answer of #bit0001 is correct. Microsoft has a list of supported versions that can be installed using this task. You can find those versions here.
As you can see, 2.1.500 is supported when installing the sdk, 2.1.0 is not, you'll need to use 2.1.300. When installing only the runtime, you can use 2.1.0. Currently, the latest 2.2 version supported is 2.2.100.

Resources