Martijn
Martijn

Reputation: 24789

Why is nuget not adding my file?

I have this nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>My.Package</id>
    <version>1.0.1.7</version>
    <title>My Package</title>
    <authors>My name</authors>
    <owners>Mu author</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>My description</description>
    <releaseNotes>Release note</releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>tag1 tag2</tags>
    <contentFiles>
      <files include="myFile.config" copyToOutput="true" />
    </contentFiles>
  </metadata>
  <files>
    <file src="myFile.config" target=""/>
  </files> 
</package>

When I pack this nuspec file, my nupkg file is created and in the NuGet Package Explorer I see that myFile.config is included in my package. All well so far.

But, then, when I install this package, the dll is added to references, but myFile.config is not added to the solution.

Things I've tried without success: - View the folder on Disk to see if myFile.config is created (not there) - <file src="myFile.config" target="."/> - <file src="myFile.config" target=".\"/>

I also want the file to set Copy to Output Directory: Copy always.

What am I missing here?

PS: I am working on a private nuget server.

Upvotes: 1

Views: 1610

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100591

The target needs to be content since files of the nugpkg's content subdirectory are copied to the consuming project.

Note that this only works for projects using the packages.config style of referencing NuGet packages. For PackageReference (available in VS 2017, default for .NET Core / ASP.NET Core / .NET Standard projects), there is a new contentFiles feature that includes files logically in the build process.

See NuGet's documentation on including content files for more information.

Upvotes: 1

Related Questions