c# - 如何使用 Stylecop Analyzer 和自定义规则集创建 nuget 包?
问题描述
我需要使用 stylecop.json 和 something.ruleset 创建一个 nuget 包,并引用 stylecop 分析器。该软件包将在所有团队中使用,以标准化 .net 的规则。我读过这个:
- 如何在 VS2017 中使用 NuGet 包发送 stylecop.json 和 custom.ruleset 文件
- https://ngeor.com/2018/03/03/how-to-use-stylecop-analyzers.html
但不幸的是,我没有正确理解如何实现这一目标。我有 stylecop.json 和 .ruleset 文件。我已完成以下步骤:
- 为 Stylecop 分析器添加了 nuget 包
- 将 stylecop.json 文件添加到解决方案中
- 将 .ruleset 文件添加到解决方案
- 在解决方案中添加了一个 nuspec 文件
我可以知道现在需要做什么来创建包含 stylecop.json 和 .ruleset 文件的 nuget 包吗?
解决方案
我可以知道现在需要做什么来创建包含 stylecop.json 和 .ruleset 文件的 nuget 包吗?
您应该在文件中添加一些关于这些文件的节点xxx.nuspec
,然后使用带有文件的nuget.exe clixxxx.nuspec
来打包您的项目。
由于您已经生成了xxxx.nuspec
文件,因此您应该将这些添加到 nuspec 文件中。
解决方案
1)您应该将这些节点添加到xxx.nuspec
文件中,并使用它,这些文件将通过 nuget 添加到新项目中。
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
.......
<contentFiles>
<files include="any/any/stylecop.json "(the relativepath of the file under the ContentFiles folder in the xxx.nupkg) buildAction="None" copyToOutput="true" flatten="false" />
<files include="any/any/xxxx.Ruleset "(the relativepath of the file under the ContentFiles folder in the xxx.nupkg) buildAction="None" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
<files>
<file src="stylecop.json(the relativePath of the file under the project)" target="contentFiles/any/any" />
<file src="xxxx.Ruleset(the relativePath of the file under the project)" target="contentFiles/any/any" />
<file src="stylecop.json(the relativePath of the file under the project)" target="content" />
<file src="xxxx.Ruleset(the relativePath of the file under the project)" target="content" />
</files>
</package>
2)记得使用这个函数,你应该使用nuget.exe
并且你应该从链接下载它,然后将它的路径设置为系统环境变量的PATH。例如,下载路径是C:\nuget\nuget.exe
,你应该C:\nuget
在PATH中设置,然后你可以在CMD中调用nuget 。
另外,我上面说的修改xxxx.nuspec
文件的时候,首先要cd到你的项目的路径,并检查该xxxx.csporj
路径下是否存在该文件。
之后,您可以nuget pack
在 CMD 中使用来打包您的项目,然后您将获得一个xxx.nupkg
nuget 包。
推荐阅读
- android - 在布局和通知栏中都有 Exoplayer 控件?
- php - 全新安装后未加载 Laravel Spark 注册视图
- c++ - Vector assign() 导致 back() 出现问题
- powershell - Powershell 按 MM/DD/YY、HH:MM AM/PM 排序
- arrays - 当某些键仅存在于几个数组中时,不确定使用 jq 过滤一组 json 数组的最有效方法 - //?
- java - 如何创建一个访问我的项目文件夹之外的文件的 Spring bean?
- javascript - 在Javascript控制台中输出姓氏的第一个字母以及大写字母的首字母?
- php - Laravel 根据变量是否为 null 执行 where 条件
- amazon-web-services - 如何在 CDK 中为基于 Lambda 的 APIGateway 提供自定义域名?
- c++ - 方法调用中带有字符串文字的 C++ const char*