Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building .sln in Azure DevOps that has both .NET Framework and .NET Core projects in the same solution file

What is the best practice for building a .sln file in Azure DevOps Pipelines that has both projects targeting .NET Core and .NET Framework?

I have tried to use the NuGet restore task on the .sln file, but it errors on some packages that are not compatible in .NET Core 2.1. It also states this in the description of the task when it is running a build:

Restore, pack, or push NuGet packages, or run a NuGet command. It supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. It uses NuGet.exe and works with .NET Framework applications. For .NET Core and .NET Standard applications, use the .NET Core task.

If I use a .NET Core task I can only do a dotnet restore and dotnet build on specific .csproj files, but not the whole .sln file like I can with the Visual Studio Build task.

What is the best practice on how to build a .sln file in Azure DevOps that has both .NET Core and .NET Framework projects and also needs to restore packages?

like image 847
Oliver Nilsen Avatar asked Jun 11 '19 15:06

Oliver Nilsen


1 Answers

Building .sln in Azure DevOps that has both .NET Framework and .NET Core projects in the same solution file

By default, .NET Framework projects use a packages.config file for NuGet references. Only the nuget.exe command line nuget restore can restore these types of projects. The .NET Core projects referencing NuGet packages using the PackageReference items can be used directly via dotnet restore. This means that dotnet restore is unable to restore packages.config based projects.

So, to resolve this issue, we could migrate from packages.config to PackageReference or just use packagereference in the .netframework project, then we could use the task dotnet restore to restore the .sln file in the Azure DevOps.

Besides, for the build, even though dotnet build should be able to build many classic .NET Framework projects, many features may not work since the underlying build tasks are meant to be run on .NET Framework and may behave differently or are completely unsupported on the .NET Core version of MSBuild, so to build the .sln file, we suggest using a Visual Studio Build task or MSBuild task.

like image 135
Leo Liu-MSFT Avatar answered Oct 17 '22 22:10

Leo Liu-MSFT