Search code examples
visual-studio.net-corenugetnuspec

NuGet include arbitrary file in project root


I have the following files (simplified for this example):

  • Library.dll
  • Data.xml

I want to create a nuspec (NuGet) file to where the Library.dll will be added as a reference and Data.xml will be copied to the root of the project that is referencing the nuget.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
    <metadata>
...
...
...
        <references>
            <reference file="Library.dll" />
        </references>
    </metadata>
    <files>
        <file src="lib\netcoreapp2.1\Library.dll" target="lib\netcoreapp2.1\Emgu.CV.World.NetStandard1_4.dll" />
        <file src="..\..\Data.xml" target="Data.xml" />
    </files>
</package>

Problem

The library is referenced however Data.xml is not copied over, what can I do to get the Data.xml file to copied over to the root of the project referencing the NuGet ?

NOTE: After the NuGet is generated, I'm adding the NuGet through Visual Studio 2017 normal "Manage NuGet Packages" option


Solution

  • What helped is going through this article: https://blog.nuget.org/20160126/nuget-contentFiles-demystified.html

    It will do a better job then me trying to explain it so get some coffee and have at it.