0

We are using nuget to package an older library (dll) file for use in our enterprise nuget share. We have done this successfully with numerous other libraries.

With the current one I'm packaging, there is a license file (.lic file) that must be copied along with the dll and xml files, but which is not getting included with the build output. Here is my <files> section from .nuspec:

<files>
    <file src="Lic\test.lic" target="lib" />
    <file src="net4.0\test.dll" target="lib" />
    <file src="net4.0\test.XML" target="lib" />
</files>

This results in all three files being packaged in the lib folder of .nupkg file (as expected). However, when the consuming project is built, the .lic file is missing from the \bin folder:

licence file missing from output

I've tried many variations of the <file> tag, and have even tried variations of the <contentFiles><files...> tag.

Does anyone have any idea how to get the .lic file to be copied with the compiled output?

Edit 6/30/2020:

Ok I have tried the technique suggested by @thatguy, but it is not working. The .lic file is not getting included in the bin folder when the project is compiled; it is not even referenced in the .nupkg file when I unzip it.

I verified my visual studio project is using PackageReferences by opening the project file. That the .lic file is missing from the .nupkg suggests an error in the .nuspec file content. Here is screenshot of my nuspec file. Is there still something awry with the tags or content? Screenshot of my .nuspec content

Novelli
  • 1
  • 3

1 Answers1

0

If you use PackageReference instead of packages.config, then you can use the contentFiles tag. It has to be contained in the metadata tag. Place content files like test.lic in a subfolders any\any\, otherwise it will not work. The following snippet will cause the content files to be copied to the output folder when building the project.

<contentFiles>
    <files include="any/any/test.lic" buildAction="None" copyToOutput="true" />
</contentFiles>

You can upgrade existing .NET Framework projects to use PackageReference. .NET Core projects will have it by default. If you cannot upgrade or you do not want to use contentFiles because of its contraints, you can also use props and targets files for MS Build. One the one hand, it is much more complex to implement and get right, on the other hand, it offers maximum flexibility and enable you to use features of MS Build which is much more beyond copying files. You can find an example for your use-case here.

thatguy
  • 21,059
  • 6
  • 30
  • 40
  • Thank you for the follow up. If I understand your answer, you're referring to converting the visual studio project to use package references instead of packages.config. Am I following you correctly? I'll need to see if the team is OK with this - most of our projects are still .net framework projects which default to packages.config - just a few projects are Core or Standard. – Novelli Jun 29 '20 at 01:43
  • You can upgrade .NET Framework projects to use `PackageReference`, you do not need .NET Core or Standard for that. I have also added an alternative, if upgrading is not an option for you. – thatguy Jun 29 '20 at 11:42