1
votes

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

1 Answers

0
votes

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.