将 xml 从 nuget 依赖项复制到输出 [英] Copy xml from nuget dependency to output
问题描述
我有一个 nuget 包,其中有一个 xml 文件,例如 config.xml
.我希望将此文件复制到任何依赖项目的 bin
文件夹中.但是,无论我如何尝试指定此文件或根据我找到的各种指南将其放在哪里,我都无法复制它.
I have a nuget package in which I have an xml file, say, config.xml
. I want this file to be copied to the bin
folder of any dependent project. However, regardless of how I try to specify this file or where I put it based on various guides I've found, I can't manage to get it copied.
如果我将我的 .nupkg
重命名为 *.nupkg.zip
并在资源管理器中查看它,它具有以下内部结构:
If I rename my .nupkg
to *.nupkg.zip
and look at it in explorer, it has the following internal structure:
package root
|-- lib
| +-- net45
| |-- My.Own.Library.dll
| +-- My.Own.Library.xml
+-- config.xml
当我构建依赖项目时,我在我的 bin 文件夹中得到了这样的东西:
When I build the dependent project, I get something like this in my bin folder:
bin
|-- My.Own.Program.exe
|-- My.Own.Library.dll
+-- My.Own.Library.xml
请注意,config.xml
未包含在此处.我如何最好从包的 nuget 规范(而不是在依赖项目中)确保 config.xml
在程序运行时复制到 bin
文件夹中建成了吗?
Note that config.xml
isn't included here. How do I, preferrably from the nuget specification of the package (rather than in the dependent project) make sure that config.xml
is copied into the bin
folder when the program is built?
一些附加信息:
我在生成 nuget 包的库的 project.json
文件中有以下规范:
I have in the project.json
file of the library which generates the nuget packge, the following specification:
"packInclude": {
"/": "config.xml",
"lib/net45/": "config.xml"
},
"contentFiles": [
"config.xml"
],
但是,这似乎不会在输出文件夹中的包中包含的 .nuspec
文件中生成任何内容.我找到了这些说明,并手动编辑生成的 .nuspec
以匹配:
However, this doesn't seem to generate anything in the .nuspec
file that is included in the package in the output folder. I found these instructions, and edited the generated .nuspec
manually to match:
<contentFiles>
<files include="contentFiles/any/any/certificates.xml" copyToOutput="true" />
</contentFiles>
这在依赖项目中根本没有任何影响.
This didn't have any effect at all in the dependent project.
推荐答案
NuPack 是一个在 MIT 许可下的开源项目,可以在本机做你需要的:
NuPack is an open source project under MIT licence that natively do what you need :
它是一个在构建时自动创建一个包的 nugget 包.您可以尝试一下,看看它如何管理您需要的功能.
It is a nugget package that automatically create a package on build time. You can try it and see how it manage the feature you need.
它似乎在 nuget 包中包含一个构建文件夹,其中包含一个 .targets 文件,以包含一个构建后过程以与依赖项文件一起复制.
It seems that it include a build folder in nuget package with a .targets file to include a post build process to copy with dependencies files.
这篇关于将 xml 从 nuget 依赖项复制到输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!