I've written an Roslyn Analyzer for a specific C# Solution and want to add the analyer to all projects in the solution via ProjectReference:
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="(MSBuildProjectDirectory)\..\..\..\CodeAnalyzers\CodeAnalyzers\CodeAnalyzers.csproj"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer" />
</ItemGroup>
</Project>
I placed this inside the Directory.Build.props file.
The Analyzer works, as long as I manually build the analyzer project before building the solution. If I don't do that I get the following warning for each project:
Warning CS8034 Unable to load Analyzer assembly C:\Users\xxx\source\repos\XYZ\CodeAnalyzers\CodeAnalyzers\bin\Debug\netstandard1.3\CodeAnalyzers.dll: Could not find file 'C:\Users\xxx\source\repos\XYZ\CodeAnalyzers\CodeAnalyzers\bin\Debug\netstandard1.3\CodeAnalyzers.dll'.
System.IO.FileNotFoundException: Could not find file 'C:\Users\xxx\source\repos\XYZ\CodeAnalyzers\CodeAnalyzers\bin\Debug\netstandard1.3\CodeAnalyzers.dll'.
File name: 'C:\Users\xxx\source\repos\XYZ\CodeAnalyzers\CodeAnalyzers\bin\Debug\netstandard1.3\CodeAnalyzers.dll'
How do I tell Visual Studio to first build the analyzer project, before trying to load the dll? Building afterwards doesn't clear the issue, I suppose because of caching.
In the Project Build Order - dialog the analyzer project is at the top and in configuration manager the checkbox for build is set.
ProjectReference
like this, won't the referenced project have a reference to itself? Do you see any other warnings during the build? – Engender