【问题标题】:How to create nuget package with Stylecop Analyzer and custom ruleset?如何使用 Stylecop Analyzer 和自定义规则集创建 nuget 包?
【发布时间】:2020-02-11 10:30:50
【问题描述】:

我需要使用 stylecop.json 和 something.ruleset 创建一个 nuget 包,并引用 stylecop 分析器。 该软件包将在所有团队中使用,以标准化 .net 的规则。 我读过这个:

但不幸的是,我没有正确理解如何实现这一目标。我有 stylecop.json 和 .ruleset 文件。我已经完成了以下步骤:

  • 为 Stylecop 分析器添加了 nuget 包
  • 将 stylecop.json 文件添加到解决方案中
  • 将 .ruleset 文件添加到解决方案中
  • 在解决方案中添加了一个 nuspec 文件

请问我现在需要做什么来创建包含 stylecop.json 和 .ruleset 文件的 nuget 包?

【问题讨论】:

标签: c# .net visual-studio nuget stylecop


【解决方案1】:

请问我现在需要做什么来创建 nuget 包 包括 stylecop.json 和 .ruleset 文件?

您应该在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,你应该在PATH中设置C:\nuget,然后你可以在CMD中调用nuget

另外,当你修改我上面说的xxxx.nuspec文件时,你应该先cd你的项目的路径,检查该路径下是否存在xxxx.csporj文件。

之后,你可以在CMD中使用nuget pack打包你的项目,然后你会得到一个xxx.nupkg,也就是nuget包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2017-01-29
    • 2011-08-26
    • 1970-01-01
    • 2019-08-15
    • 2017-11-26
    • 2019-06-12
    相关资源
    最近更新 更多