Search code examples
c#msbuildroslyn-code-analysis

Ho to add project to all solution projects except itself?


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?


Solution

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