Support for .NET-Standard / .NET Core
Since #17955 (closed) it is possible to set the TargetFrameworkVersion
property. This is fine when using .NET-Framework.
But when it is compiled against/for .NET-Core or .NET-Standard, TargetFramework
property must be set instead of the TargetFrameworkVersion
property. (Without Version)
If there is one external project integrated with include_external_msproject
and this project uses TargetFramework (not TargetFrameworkVersion) following error is thrown during build of ALL_BUILD target:
Project 'XXX' targets 'netstandard2.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.0'.
The error is thrown because the ALL_BUILD target references the external project and both uses a incompatible dotnet standard.
It is possible to hide the error by use of: set_target_properties(<TARGET> PROPERTIES EXCLUDE_FROM_ALL 1)
But now the target is not build by default, therefore it does not solve the problem.
My proposal for making cmake fit for support of .NET Core or any other new implementation of the standard (see also here):
My proposal is that beside CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION
cmake property also CMAKE_DOTNET_TARGET_FRAMEWORK
property is provided.
As they are not able to coexists I would say: If CMAKE_DOTNET_TARGET_FRAMEWORK
is set it wins against CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION
.
Alternative a switch should be somehow possible.
Example (taken from here):
Depending on the target framework, it can be represented in the following ways in the project file:
- For a .NET Core app:
<TargetFramework>netcoreapp2.1</TargetFramework>
- For a .NET Standard app:
<TargetFramework>netstandard2.0</TargetFramework>
- For a .NET Framework app:
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
My proposal for solving the problem with the build error:
Set the SkipGetTargetFrameworkProperties
property of the project reference at ALL_BUILD target to true
.
The result looks like:
<ProjectReference Include="<Path-To-Project>\<Project-Name>.csproj">
<Project>{<Project-UUID>}</Project>
<Name><Project-Name></Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties> <!-- this is new, default is false -->
</ProjectReference>
I think this is possible for all references of the ALL_BUILD project, because there is no need to link them. They are just build-dependencies.