2

我正在创建一个多平台应用程序。我有一个多目标的共享库(针对.netstandard 2.0和.NET 4.5)...查看项目文件:Visual Studio Community 2017中的条件引用

<PropertyGroup> 
    <TargetFrameworks>netstandard2.0;net45</TargetFrameworks> 
    </PropertyGroup> 

当我建立在Windows的Visual Studio 2017年的项目,我得到两个目录中输出(netstandard2.0,net45)和相应的dll。构建是成功的。

当我建立在Visual Studio 2017年完全相同的项目(相同的代码)在Mac上,我得到这个性质的错误:

类型“OptionAttribute”两个“CommandLine.DotNetStandard,版本存在= 1.0.30' 和 '的CommandLine,版本= 1.9.71.2'

我有条件地以下面的方式引用的命令行分析器库:

<!-- CommandLineParser library --> 
    <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> 
    <PackageReference Include="CommandLine.DotNetStandard"> 
     <Version>1.0.3</Version> 
    </PackageReference> 
    </ItemGroup> 

    <ItemGroup Condition="'$(TargetFramework)' == 'net45'"> 
    <PackageReference Include="CommandLineParser"> 
     <Version>1.9.71</Version> 
    </PackageReference> 
    </ItemGroup> 

这适用于Windows,但在Mac上它看起来并不遵守条件。这是在mac上的视觉工作室的已知错误?难道我做错了什么?

回答

4

Visual Studio忽略这些情况下的情况。使用Choose/When相反,应该全力支持:https://msdn.microsoft.com/en-us/library/ms164282.aspx

<Choose> 
    <When Condition=" '$(TargetFramework)' == 'netstandard2.0' "> 
    <ItemGroup> 
     <PackageReference Include="CommandLine.DotNetStandard"> 
     <Version>1.0.3</Version> 
     </PackageReference> 
    </ItemGroup> 
    </When> 
    <When Condition=" '$(TargetFramework)' == 'net45' "> 
    <ItemGroup> 
     <PackageReference Include="CommandLineParser"> 
     <Version>1.9.71</Version> 
     </PackageReference> 
    </ItemGroup> 
    </When> 
</Choose> 
+0

没错,但太糟糕了,根本的MSBuild默默地忽略的条件,从而掩盖了真正的问题。 –

相关问题