Nuget package issues - buildAction, copyToOutput, flatten are ignored
Package project (ThisProject.vbproj)- .Net Standard Library 2.0, .nuspec file:
<references>
<reference file="ThisProject.dll"></reference>
<reference file="First.dll"></reference>
<reference file="Second.dll"></reference>
<reference file="...."></reference>
</references>
<contentFiles>
<files include="any/any/*" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
<files>
<file src="contentFiles\any\any\First.dll" target="lib\any\any\First.dll"></file>
<file src="contentFiles\any\any\Second.dll" target="lib\any\any\Second.dll"></file>
<file src="contentFiles\any\any\....dll" target="lib\any\any\.....dll"></file>
</files>
When importing in .net ClickOnce Framework 4.6.1 Project, the contentFiles are still in the subfolders (flatten is ignored), Build Action and CopyToOutputDirectory are the defaults (buildAction,copyToOutput are ignored)
Read all the documentation I could find e.g.
https://learn.microsoft.com/en-us/nuget/reference/nuspec
What am I doing wrong?
I think you have some misunderstanding about this part.
First, contentFiles works for new-sdk projects(
Net CoreandNet Standard) with PackageReference nuget management format rather thanNet Frameworkproject with packages.config nuget management format.And
contentFilesworks for content files rather than lib folder. So you should not pack these dll files ontarget="lib\any\any\.....dll". You should pack them intocontentFilesfolder.Use this:
Then, you should install this nuget package on a Net Core project.
When you finish it, repack the project with
nuget packcommand, then, before you install the new one, clean the nuget caches first to remove the old previous version. Then, install the new version on a Net Core project and you can see the effect like this:======================================================================
If you still want to have this function on a
Net Frameworkproject, you should pack these files oncontentnode rather thancontentFiles.And you only need to add two lines:
But these simply cannot change the attributes of the imported file. And for net framework project, changing the property of the files cannot be done on
xxx.nuspecfile.You should use <packages_id>.props or targets file.
1) create a file called
<packages_id>.propsunder the build folder on the Solution Explorer, if your nuget package is named asThisProject.1.0.0.nupkg, you should name it asThisProject.propsso that it will work.This is mine:
2) add these on the props file:
3) add a line on
nuspecfile to include the props file into the nupkg.4) then repack the nuget package, clean the nuget caches, then install this new one on the Net Framework project with
packages.config.Note: although the Properties window of the imported content file on the solution explorer does not show the changed value and still shows the old one, the files are already copied into the output folder of the project. And it is an UI display issue on Solution Explorer and the changed values are already be used and work well. So you do not have to care much about that.