如何使用 Stylecop Analyzer 和自定义规则集创建 nuget 包?
How to create nuget package with Stylecop Analyzer and custom ruleset?
我需要使用 stylecop.json 和 something.ruleset 创建一个 nuget 包,并引用 stylecop 分析器。
这个包将在所有团队中使用,以标准化 .net 的规则。
我读过这个:
但不幸的是我没有正确理解如何实现这一点。我有 stylecop.json 和 .ruleset 文件。我已经完成了以下步骤:
- 为 Stylecop 分析器添加了 nuget 包
- 将 stylecop.json 文件添加到解决方案
- 将 .ruleset 文件添加到解决方案
- 向解决方案添加了 nuspec 文件
请问现在需要做什么来创建包含 stylecop.json 和 .ruleset 文件的 nuget 包?
May I please know what need to be done now to create the nuget package
including the stylecop.json and .ruleset file?
您应该在 xxx.nuspec
中添加关于这些文件的一些节点,然后使用 nuget.exe cli 和 xxxx.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
,你应该从link下载,然后设置它的路径到PATH系统环境变量。例如,下载路径是C:\nuget\nuget.exe
,你应该在PATH中设置C:\nuget
然后你可以调用nuget在 CMD 中。
除此之外,刚才我说的修改xxxx.nuspec
文件时,你应该先cd你的项目路径,查看是否有xxxx.csporj
文件存在于该路径下。
之后,你可以在CMD中使用nuget pack
打包你的项目,然后你会得到一个xxx.nupkg
,也就是nuget包。
我需要使用 stylecop.json 和 something.ruleset 创建一个 nuget 包,并引用 stylecop 分析器。 这个包将在所有团队中使用,以标准化 .net 的规则。 我读过这个:
但不幸的是我没有正确理解如何实现这一点。我有 stylecop.json 和 .ruleset 文件。我已经完成了以下步骤:
- 为 Stylecop 分析器添加了 nuget 包
- 将 stylecop.json 文件添加到解决方案
- 将 .ruleset 文件添加到解决方案
- 向解决方案添加了 nuspec 文件
请问现在需要做什么来创建包含 stylecop.json 和 .ruleset 文件的 nuget 包?
May I please know what need to be done now to create the nuget package including the stylecop.json and .ruleset file?
您应该在 xxx.nuspec
中添加关于这些文件的一些节点,然后使用 nuget.exe cli 和 xxxx.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
,你应该从link下载,然后设置它的路径到PATH系统环境变量。例如,下载路径是C:\nuget\nuget.exe
,你应该在PATH中设置C:\nuget
然后你可以调用nuget在 CMD 中。
除此之外,刚才我说的修改xxxx.nuspec
文件时,你应该先cd你的项目路径,查看是否有xxxx.csporj
文件存在于该路径下。
之后,你可以在CMD中使用nuget pack
打包你的项目,然后你会得到一个xxx.nupkg
,也就是nuget包。