msbuildconditional-statementspackagereferenceitemgroup

Package reference condition - exclude for some project


I have the following entry in Package.props file on solution level:

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

How should I edit this so that reference for StyleCop will be excluded for some project? Something like:

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

So I would like that 'MyAwsomeProject' will not have a reference to StyleCop.


Solution

  • I managed to get it working like this:

    <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>