NuGet restore package with xml file content - Working sample?

对着背影说爱祢 提交于 2019-12-24 07:26:11

问题


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

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

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?

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

A working sample would help a lot.


回答1:


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

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>

Below are the detail steps:

  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>
    
  4. Use nuget.exe pack "..\TestNuGetPackage.csproj.nuspec" to create a package.

  5. 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.



来源:https://stackoverflow.com/questions/44288689/nuget-restore-package-with-xml-file-content-working-sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!