Jak*_*ake 11 .net visual-studio nuget
我想用一个文件创建一个nuget包.有没有办法打包单个文件,然后指示文件在Visual Studio项目中的位置?
我能够创建一个nuspec文件并打包一个包含相关文件的nuget包.但是,不能将其安装在包装内.
更具体地说:我有一个配置文件,在许多项目中应该是相同的.我希望能够安装一个nuget包,可以安装它们以将配置文件放在正确的位置.
nuspec文件现在只是指定元数据的基础知识.然后我使用该nuspec文件和目录中的配置文件运行nuget pack.这会导致nuget包中包含配置文件,该文件是可卸载的.
这是我现在在nuget包中的内容:

和nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>StyleCopSettings</id>
<version>1.0.1</version>
<title>StyleCopSettings</title>
<authors>Clearspan</authors>
<owners>Clearspan</owners>
<description>StyleCopSettings</description>
</metadata>
</package>
Run Code Online (Sandbox Code Playgroud)
问题是你没有在你的nuspec中引用有问题的文件.我编辑了你的nuspec如下.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>StyleCopSettings</id>
<version>1.0.1</version>
<title>StyleCopSettings</title>
<authors>Clearspan</authors>
<owners>Clearspan</owners>
<description>StyleCopSettings</description>
</metadata>
<files>
<file src="$pathToYourFile$\styleCopSettings.txt" target="content\Settings" />
</files>
</package>
Run Code Online (Sandbox Code Playgroud)
要通过包将文件添加到项目,必须将其添加到包的内容目录中target="content\Settings".nuget包的content目录的作用类似于将安装包的项目的根目录(source).因此,通过在目标中指定更多目录,我们可以将文件放在特定位置.在上面的示例中,该styleCopSettings.txt文件将放置在使用此包的任何项目的Settings目录中.设置目录将作为安装的一部分添加.
在你的nuspec上调用nuget pack后,你应该得到类似的东西

当您使用该包时,您将得到以下结果.

| 归档时间: |
|
| 查看次数: |
1463 次 |
| 最近记录: |