[英]Multi-targeting `net461` and `netcoreapp2.0`
I have a command line .NET application that should compile against only ported .NET Core components when built as a .NET core app, but can additionally reference legacy .NET framework modules when built that way.我有一个命令行 .NET 应用程序,当构建为 .NET Core 应用程序时,它应该只针对移植的 .NET Core 组件进行编译,但在以这种方式构建时还可以引用旧版 .NET 框架模块。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<ProjectGuid>{48B4C337-CD13-4826-B6A1-DA97CE71511B}</ProjectGuid>
<RootNamespace>Microsoft.Pc</RootNamespace>
<AssemblyName>Pc</AssemblyName>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<OutputPath>$(PSdkFolder)\Binaries</OutputPath>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<ProjectReference Include="..\CompilerCore\CompilerCore.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<ProjectReference Include="..\CompilerCore\CompilerCore.csproj" />
<ProjectReference Include="..\LegacyCompiler\LegacyCompiler.csproj" />
<ProjectReference Include="..\CompilerService\CompilerService.csproj" />
</ItemGroup>
</Project>
Despite this, I get these errors尽管如此,我还是收到了这些错误
"D:\Source\Repos\P\P.sln" (default target) (1) ->
"D:\Source\Repos\P\Src\Pc\CommandLine\CommandLine.csproj.metaproj" (default target) (20) ->
"D:\Source\Repos\P\Src\Pc\CommandLine\CommandLine.csproj" (default target) (21) ->
"D:\Source\Repos\P\Src\Pc\CommandLine\CommandLine.csproj" (Build target) (21:3) ->
(_GetProjectReferenceTargetFrameworkProperties target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(1601,5): error : Project 'D:\Source\Repos\P\Src\Pc\LegacyCompiler\LegacyCompiler.csproj' targets 'net461'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v2.0'. [D:\Source\Repos\P\Src\Pc\CommandLine\CommandLine.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(1601,5): error : Project 'D:\Source\Repos\P\Src\Pc\CompilerService\CompilerService.csproj' targets 'net461'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v2.0'. [D:\Source\Repos\P\Src\Pc\CommandLine\CommandLine.csproj]
Why is it complaining that LegacyCompiler.csproj targets 'net461' while CommandLine targets '.NETCoreApp,Version=v2.0' when that dependency should be excluded in this case?为什么在这种情况下应该排除该依赖项时抱怨 LegacyCompiler.csproj 以“net461”为目标,而 CommandLine 以“.NETCoreApp,Version=v2.0”为目标?
Update: these are the .csproj
files for the other projects.更新:这些是其他项目的
.csproj
文件。 As this project is open-source, I'm posting links to the files:由于这个项目是开源的,我发布了文件的链接:
您应该将.Net Standard
类库与.Net Core
和.Net 4.6.1
支持的版本一起使用(我可能从您的.csproj
文件中猜到)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.