【发布时间】:2020-03-05 03:06:37
【问题描述】:
我在使用 NuGet v4 CLI 将文件复制到输出时遇到问题。
我的目录结构如下:
repo
repo\CodeAnalyzer.nuspec
repo\CodeAnalyzer.props
repo\contentFiles\any\any\StyleCop.ruleset
这是我的 CodeAnalyzer.props 文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PackageName>CodeAnalyzer</PackageName>
<PackageVersion>0.1.0</PackageVersion>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>
和 CodeAnalyzer.nuspec 文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>CodeAnalyzer</id>
<description>Provides standard code analyzer tooling and customisation.</description>
<authors>Me</authors>
<version>0.1.0</version>
<dependencies>
<dependency id="StyleCop.Analyzers" version="1.1.118" />
</dependencies>
<contentFiles>
<files include="any/any/*" buildAction="Content" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
<files>
<file src="contentFiles\any\any\StyleCop.ruleset" target="contentFiles" />
<file src="CodeAnalyzer.props" target="build" />
</files>
</package>
在 CLI 上我正在使用:
.\nuget.exe pack .\CodeAnalyzer.nuspec
在生成的 .nupkg 中,有一个 contentFiles 目录,其中包含 StyleCop.ruleset 文件,这样就可以了。
如果我随后将包安装到项目中,它会很好地获取 StyleCop.Analyzers 依赖项,并查找 StyleCop.ruleset 文件,因此 .props 文件很好。
但是 StyleCop.ruleset 文件没有放在任何地方。
感觉我已经尝试了很多将 buildActions 更改为 None/Content、copyToOutput 为 true/false、contentFiles.file 元素和 file.file 元素的不同路径。
编辑:消费项目正在为 NuGet 包使用 PackageReferences,而不是 packages.config。
【问题讨论】:
标签: nuget nuget-package nuget-package-restore nuget-spec