通过nuget包添加代码分析规则集 [英] Add code analysis ruleset through nuget package
问题描述
我正在尝试构建一个NuGet软件包,该软件包可以自动且可更新地添加我们公司的代码分析词典。
I'm trying to build a NuGet package that adds our company's code analysis dictionary automatically and updatable.
规则集已添加到内容文件夹中,现在我想要使用install.ps1脚本在项目文件中添加规则集。
我想出了办法,就是使用envDTE,但是我找不到关于它的很多有用的文档。
http://msdn.microsoft.com/zh-CN/library/za2b25t3(v = vs.100).aspx
The rule set is added in the content folder and now I want to use the install.ps1 script to add the rule set in the project file.
I figured out the way to go would be to use the envDTE, but I can't find much useful documentation about it other then this overwhelming object graph in which I can't find the CodeAnalysisRuleset node.
http://msdn.microsoft.com/en-us/library/za2b25t3(v=vs.100).aspx
我追求正确的路径吗?
关于在NuGet powershell中如何使用envDTE有任何相关的教程/文档吗?
我如何运行/调试我的安装脚本,而不必将其实际添加到软件包中并针对项目进行安装?
Am I pursuing the right path?
Is there any relevant tutorial/documentation on how to use the envDTE in NuGet powershell?
How can I run/debug my install script without having to actually add it to a package and install it against a project?
侧注
尽管@Nicole C alinoiu显示了更好的方法,稍后可以使用这些信息:
Sidenote
Although @Nicole Calinoiu showed the better way, this morsel of information might come in handy later on:
foreach ($config in $project.ConfigurationManager){
$config.Properties.Item("CodeAnalysisRuleSet").Value = "myruleset.ruleset"
}
推荐答案
无需编写脚本。规则集和字典都可以通过导入的MSBuild .props
文件进行注册,如此处 https://docs.microsoft.com/zh-cn/ nuget / create-packages / creating-a-package#include-msbuild-props-and-targets-a-package
There's no need to script this. Both the ruleset and dictionary can be registered via an imported MSBuild .props
file, as described here https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#include-msbuild-props-and-targets-in-a-package
例如,您的NuGet源文件夹结构可能看起来像这样(假设 CodeAnalysisSettings是您的软件包ID):
For example, your NuGet source folder structure might look like this (assuming "CodeAnalysisSettings" is your package ID):
- build
- CodeAnalysisSettings.props
- MyCustomDictionary.xml
- MyRules.ruleset
,其中
CodeAnalysisSettings.props
的内容类似于以下内容:where the contents of
CodeAnalysisSettings.props
are something like the following:<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <RunCodeAnalysis>true</RunCodeAnalysis> <CodeAnalysisRuleSet>MyRules.ruleset</CodeAnalysisRuleSet> </PropertyGroup> <ItemGroup> <CodeAnalysisDictionary Include="MyCustomDictionary.xml" /> </ItemGroup> </Project>
这篇关于通过nuget包添加代码分析规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!