我有一个命令行.NET应用程序,当构建为.NET核心应用程序时,它应该仅针对移植的.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>
尽管如此,我还是遇到了这些错误
"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]
为什么抱怨LegacyCompiler.csproj的目标是&#39; net461&#39; CommandLine的目标是&#39; .NETCoreApp,Version = v2.0&#39;什么时候应该排除这种依赖?
更新:这些是其他项目的.csproj
个文件。由于这个项目是开源的,我发布了文件链接:
答案 0 :(得分:0)
您应该将.Net Standard
类库与.Net Core
和.Net 4.6.1
都支持的版本一起使用(我可能从您的.csproj
文件中猜到)。