带有XML文件内容的NuGet还原程序包-工作示例吗? [英] NuGet restore package with xml file content - Working sample?

查看:90
本文介绍了带有XML文件内容的NuGet还原程序包-工作示例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的工具:Visual Studio 2015 Enterprise,Nuget 3.5,.NET Framework 4.0

Tools Used: Visual Studio 2015 Enterprise, Nuget 3.5, .NET Framework 4.0

有人有一个包含一些xml文件和dll库的NuGet软件包的工作示例吗?

Does anyone have a working sample of a NuGet Package that includes some xml files as well as dll libraries?

我在许多地方都读过零星的笔记,但是还没有找到有效的样本.关于xml文件是属于net文件夹还是属于content文件夹,似乎存在争议.我还读到我们需要某种Power Shell脚本来在安装软件包时将文件复制到bin中?

I have read scattered notes about this in many places, but I have yet to find a working sample. There seems to be debate as to whether xml files belong in net folder or in content files folder. I am also reading that we require some sort of power shell script to copy the file into bin when the package installs?

安装软件包时,xml必须与dll一起位于BIN文件夹中.

The xml has to be in the BIN folder with the dlls when the package installs.

一个有效的样本会很有帮助.

A working sample would help a lot.

推荐答案

安装软件包时,xml必须与dll一起位于BIN文件夹中.

The xml has to be in the BIN folder with the dlls when the package installs.

如果要将NuGet包中的xml文件与dll分发到同一文件夹中,则需要将它们添加到.nuspec文件中,例如:

If you want distribute your xml files with your NuGet package in the same folder as your dlls, you will need to add them to your .nuspec file, for example:

<files>
<file src="bin\Debug\TestNuGetPackage.dll" target="lib\Net462" />
<file src="bin\Debug\TestNuGetPackage.xml" target="lib\Net462" />
</files>

下面是详细步骤:

  1. 创建一个空白的C#类库项目,在文件资源管理器中打开该项目.
  2. 使用nuget spec "..\TestNuGetPackage.csproj"创建TestNuGetPackage.csproj.nuspec文件.
  3. 修改.nuspec文件,以下是我的.nuspec文件:

  1. Create a blank C# Class Library project, open the project in the File Explorer.
  2. Use nuget spec "..\TestNuGetPackage.csproj" to create TestNuGetPackage.csproj.nuspec file.
  3. Modify the .nuspec file, below is my .nuspec file:

<?xml version="1.0"?>
<package >
 <metadata>
   <id>TestNuGetPackage</id>
   <version>1.0.0</version>
   <authors>Tester</authors>
   <owners>Tester</owners>
   <requireLicenseAcceptance>false</requireLicenseAcceptance>
   <description>A description of your library</description>
   <releaseNotes>Release notes for this versio</releaseNotes>
   <copyright>Copyright 2017</copyright>
   <tags>Tag1 Tag2</tags>
 </metadata>
<files>
  <file src="bin\Debug\TestNuGetPackage.dll" target="lib\Net462" />
  <file src="bin\Debug\TestNuGetPackage.xml" target="lib\Net462" />
</files>
</package>

  • 使用nuget.exe pack "..\TestNuGetPackage.csproj.nuspec"创建一个程序包.

  • Use nuget.exe pack "..\TestNuGetPackage.csproj.nuspec" to create a package.

    使用.net Framework 4.62创建测试项目,然后将该软件包安装到项目中并进行构建,您将发现xml文件必须位于dll所在的BIN文件夹中.

    Create a test project with .net framework 4.62, then install that package to the project and build it, you will find the xml file has to be in the BIN folder with the dlls.

    这篇关于带有XML文件内容的NuGet还原程序包-工作示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆