How to create a multi-purpose solution for .NET Core?

I have a solution with multi-purpose csproj files:

<PropertyGroup> <TargetFrameworks>net45;netstandard1.6</TargetFrameworks> </PropertyGroup> 

or

 <PropertyGroup> <TargetFrameworks>net45;netcoreapp1.1</TargetFrameworks> </PropertyGroup> 

I am trying to create a .NET Core part of this solution on Linux, but I cannot manage it. If I run

 dotnet build 

It builds all goals: netcoreapp1.1 , netstandard1.6 and net45 and fails on net45 because .NET Core does not provide the .NET 4.5 platform on Linux. I tried to solve this problem by specifying mono as the basis for building, but the solution is complex, and not all .NET 4.5 is supported in mono. However, this can help someone else avoid can't find .NETFramework v4.5 just starting:

 FrameworkPathOverride=/usr/lib/mono/4.5/ dotnet restore FrameworkPathOverride=/usr/lib/mono/4.5/ dotnet build 

When I run dotnet build /p:TargetFramework=netcoreapp1.1 , I get a lot of errors, I think, because projects with netstandard1.6 were not built.

If i pass

  dotnet build /p:TargetFrameworks=netcoreapp1.1\;netstandard1.6 

I get

 MSBUILD : error MSB1006: Property is not valid. Switch: netstandard1.6 

How can I pass netcoreapp1.1 and netstandard1.6 target frameworks simultaneously to msbuild from the command line?

I know that I can add an additional property and make conditional compilation depending on it, but I do not want to modify csproj to make this workaround.

+5
source share
1 answer

If you really don’t even want to create full-fledged frameworks or PCL versions on Linux and just want to use the basic .net application or the standard .net library, you can change the project file ( .csproj ) only to multi-target windows and behave like a project, aimed at a single structure on non-windows, for example:

 <PropertyGroup> <TargetFrameworks>netcoreapp1.1;net45</TargetFrameworks> <TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp1.1</TargetFrameworks> </PropertyGroup> 

This allows you to specify netstandard* and netcoreapp* for separate windows separately for all projects, and the main versions of your .net kernel can only be created using simple dotnet restore / dotnet build .

+2
source

Source: https://habr.com/ru/post/1267044/


All Articles