通过nuget包添加代码分析规则集

编程入门 行业动态 更新时间:2024-10-25 18:23:26
本文介绍了通过nuget包添加代码分析规则集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试构建一个NuGet软件包,该软件包可以自动且可更新地添加我们公司的代码分析词典。

I'm trying to build a NuGet package that adds our company's code analysis dictionary automatically and updatable.

规则集已添加到内容文件夹中,现在我想要使用install.ps1脚本在项目文件中添加规则集。 我想出了办法,就是使用envDTE,但是我找不到关于它的很多有用的文档。 msdn.microsoft/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. msdn.microsoft/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 文件进行注册,如此处 docs.microsoft/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 docs.microsoft/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="schemas.microsoft/developer/msbuild/2003"> <PropertyGroup> <RunCodeAnalysis>true</RunCodeAnalysis> <CodeAnalysisRuleSet>MyRules.ruleset</CodeAnalysisRuleSet> </PropertyGroup> <ItemGroup> <CodeAnalysisDictionary Include="MyCustomDictionary.xml" /> </ItemGroup> </Project>

更多推荐

通过nuget包添加代码分析规则集

本文发布于:2023-11-10 09:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575071.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:规则   代码   nuget

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!