0

I have analyzers project in my solution.

I also use Directory.Build.props file.

I'd like to reference analyzer project by all projects (except analyzer and its tests).

What condition can I use for it? It is possible to get referencing project?

Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
  • 1
    You could use `$(MSBuildProjectFile)` which is the project being built but that's not super generic (though maybe that's ok for your case); alternative would be to figure out which property distinguishes an analyzer project from another one, on the other hand that property might not yet be available in Directory.build.props because it gets imported early – stijn Nov 24 '21 at 10:10

1 Answers1

1

Thanks to stijn comment, I found the solution:

    <ItemGroup>
        <ProjectReference 
          Include="..\Analyzers\GlobalAnalyzers\GlobalAnalyzers.csproj" 
          Condition="!$(MSBuildProjectDirectoryNoRoot.Contains('Analyzers/'))">
            <PrivateAssets>all</PrivateAssets>
            <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
            <OutputItemType>Analyzer</OutputItemType>
        </ProjectReference>
    </ItemGroup>
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137