软件包参考条件-排除某些项目

时间:2020-03-25 15:30:29

标签: msbuild conditional-statements packagereference itemgroup

我在解决方案级别的Package.props文件中具有以下条目:

<ItemGroup Label="My Label" Condition=" '$(SHFBSchemaVersion)' == '' ">
    <PackageReference Include="StyleCop.Analyzers">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>    
  </ItemGroup>

我应该如何编辑它,以便在某些项目中排除StyleCop的引用?像这样:

<ItemGroup Label="My Label" Condition=" '$(SHFBSchemaVersion)' == '' " Exclude="MyAwsomeProject">

所以我希望'MyAwsomeProject'没有对StyleCop的引用。

1 个答案:

答案 0 :(得分:0)

我设法使它像这样工作:

<ItemGroup Label="My Label" Condition=" '$(SHFBSchemaVersion)' == ''  And '$(AssemblyName)' != 'MyAwsomeProject'">
    <PackageReference Include="StyleCop.Analyzers">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>    
</ItemGroup>