nugetnuget-packagenuget-spec

nuget not installing file in project\bin directory


Working in VS 2019 .NET framework 4.8 For my C# class library project, I ran nuget spec to create a nuspec file for the dll and its dependencies:

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>MyId</id>
    <version>1.0.0</version>
    <title>MyTitle</title>
    <authors>Me</authors>
    ....
    <dependencies>
      <dependency id="dll1" version="1.0.0" />
      <dependency id="dll2" version="2.0.0" />
    </dependencies>
  </metadata>
</package>

No problems building the nuget package. In my consuming project (MyProject), I installed that package, and after building MyProject, the class library dll and the dependency files are placed in the MyProject\bin directory. Great.

However I need to get another file into directory MyProject\bin, let's call that file MyFile.txt. I first tried using the element:

  ..... 
      <dependency id="dll2" version="2.0.0" />
    </dependencies>
  </metadata>
  <files>
   <file src="MyFile.txt" target="lib" />
  </files>
</package>

No luck. While the file is in the packages\lib folder, it does not get placed in MyProject\bin.

I then removed the element and tried the element within the tag:

  .....  
    <contentFiles>
      <files include="MyFile.txt" buildAction="None" copyToOutput="true" flatten="true" />
    </contentFiles>
  </metadata>
</package>

No luck that way either. Is there a way to accomplish what I need to do? It looks like it may involve having some folders in my class library root folder, but not sure what folders (content?) or how to properly reference them in the nuspec file. Thanks.


Solution

  • Neglected to update this post with the answer I found. Using the <files><file /></files> logic is what solved it. It involved the use of the target attribute and using the content keyword in the value:

      <files>
        <file src="content\bin\MyFile.txt" target="content\bin" />
      </files>
    

    It's in the documentation, I unfortunately missed that even upon multiple readings. See https://learn.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element