【发布时间】:2022-01-18 01:04:09
【问题描述】:
我为特定的 C# 解决方案编写了一个 Roslyn 分析器,并希望通过 ProjectReference 将分析器添加到解决方案中的所有项目:
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="(MSBuildProjectDirectory)\..\..\..\CodeAnalyzers\CodeAnalyzers\CodeAnalyzers.csproj"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer" />
</ItemGroup>
</Project>
我把它放在 Directory.Build.props 文件中。
只要我在构建解决方案之前手动构建分析器项目,分析器就可以工作。如果我不这样做,每个项目都会收到以下警告:
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'
我如何告诉 Visual Studio 先构建分析器项目,然后再尝试加载 dll? 之后构建并不能解决问题,我想是因为缓存。
在“项目构建顺序”对话框中,分析器项目位于顶部,而在配置管理器中,构建的复选框已设置。
【问题讨论】:
-
如果像这样添加
ProjectReference,被引用的项目不会有对自身的引用吗?您在构建过程中是否看到任何其他警告?
标签: c# .net visual-studio roslyn roslyn-code-analysis