官方文档:Install FxCop analyzers in Visual Studio
1.安装 & 设置成功
2.release版本中删除相关Dll =》项目需要放到docker中,避免每次提交image过大,降低工作效率,故仅在debug时,才加入dll。
2.2.1 方式:编辑项目文件.csproject
修改相关condition :
其他为程序自动添加;
手动修改部分: And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.8\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists(‘..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.8\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props‘) And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘ " /> <Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.8\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists(‘..\packages\Microsoft.NetFramework.Analyzers.2.9.8\build\Microsoft.NetFramework.Analyzers.props‘) And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘" /> <Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.8\build\Microsoft.NetCore.Analyzers.props" Condition="Exists(‘..\packages\Microsoft.NetCore.Analyzers.2.9.8\build\Microsoft.NetCore.Analyzers.props‘) And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘" /> <Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.8\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists(‘..\packages\Microsoft.CodeQuality.Analyzers.2.9.8\build\Microsoft.CodeQuality.Analyzers.props‘) And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘" /> <Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.8\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists(‘..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.8\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props‘) And ‘$(Configuration)|$(Platform)‘ == ‘Debug|AnyCPU‘" />
3.release检测:
bin文件夹中,相关dll查询不到了
扩展:
如果condition 条件为or:
Condition="‘$(Configuration)‘==‘Debug‘ Or ‘$(Configuration)‘==‘Release‘"
参考文档:Project reference conditional include with multiple conditions
原文地址:https://www.cnblogs.com/panpanwelcome/p/12430099.html
时间: 2024-11-02 12:32:57