如何在 .NET Core 3.0 SDK 上构建的同时多目标 .NET 5 和 .NET Core 3.1

问题描述

我正在尝试升级我的项目以支持 .NET 5,同时仍在构建 .NET Core 3.1 工具集。

我尝试将 .NET 5 TFM ( My project structure is like com.ABD/Src/com/sp/gateway/Abc.java file. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <target> <echo message=">>>>>>>>>compile" /> <mkdir dir="bin" /> <javac srcdir="com.sc.lms.gateway/src" destdir="bin" classpathref="classpath" source="8" target="8" /> <copy todir="bin"> <fileset dir="WebContent"> <include name="**/*.xml" /> </fileset> </copy> </target> </configuration> </plugin> ) 添加到我的目标框架中。

.net5.0

不幸的是,这会导致在仅安装了 .NET Core 3.1 工具集的机器上运行时构建失败。

<TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>

我正在尝试找到一个条件,以便我可以仅在可用时定位 error MSB3971: The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK. ,但文档很少。

解决方法

这根本不可能。

新的 SDK(例如 5.0)可以通过较旧的 TargetFrameworknetcoreapp2.1netcoreapp3.1 等)定位较旧的运行时。

较旧的 SDK 无法通过新的 TargetFramework 来定位较新的运行时。