我在使用NuGet v4 CLI时,NuGet无法将文件复制到输出目录。
我的目录结构如下:
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元素等。
编辑:消费项目使用PackageReferences来获取NuGet packages,而不是packages.config。
<contentFiles><files include="**/*.*" buildAction="None" copyToOutput="true" flatten="true" /></contentFile>
和<file src="content\**" target="contentFiles\any\any" />
.. 然后在.props文件中使用了<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)..\content\StyleCop.ruleset</CodeAnalysisRuleSet>
.. 无法编辑stylecop文件实际上是理想的,因为它将防止人们进行意外更改。谢谢! - jacob21