Include non-Solution items in Nuget package - nuget

I have created a Nuspec file with the following files elements:
<files>
<file src="lib\" target="lib" />
<file src="tools\" target="tools" />
<file src="content\" target="content" />
<file src="other-stuff\" target="content" />
</files>
When I restore this Nuget package to any project, the contents of the other-stuff folder is added to the project (as expected).
Is there any way to ensure this content is placed on the filesystem, but not added to the project / solution? I don't want this content to show in Visual Studio.

There is no way to create a folder with no content in the nuspec file. However, you can definitely do this using a install.ps1 file. You can find many examples by searching for "nuget install.ps1" and utilizing powershell code to create a directory.

Related

Nuget not including mscorlib.dll

Nuget ignores adding references to a project when the DLL is named mscorlib.dll. Any way force nuget to add a references to the project, or copy the DLL to the bin output directory?
Here's the snippet from the .nuspec file:
<files>
<file src="..\..\bin\mscorlib.dll" target="lib\net45" />
</files>
The necessity is for deploying an alternative implementation of mscorlib.

How can a files without extensions be renamed through Nuspec

The .nuspec File Reference says that files without extensions can be selected in the following manner:
To include files without an extension, use the * or ** wildcards:
<file src="flags\**" target="flags" />
And, then also says that files can be rename in this manner:
<file src="ie\css\style.css" target="Content\css\ie.css" />
How can both this functions be combined to rename LICENSE to AssemblyName.license.txt? I have tried the following without any success:
<files>
<file src="../LICENSE*" target="./NHibernate.license.txt" />
-AND-
<file src="../LICENSE**" target="./NHibernate.license.txt" />
</files>
You cannot rename files using wildcard. To do what you would like to do, you will need to list out each file individually in the .nuspec file.
<file src="../LICENSE1" target="./1.license.txt" />
<file src="../LICENSE2" target="./2.license.txt" />
If you are frequently adding license files, you may wish to continue making a copy of all files before packing.

Nuspec buildAction not applying to contentFiles

I've been recently trying to create a .nuspec file that attaches a .dll file as an Embedded Resource. To do so, I've used the contentFiles tag on metadata, setting the buildAction="EmbeddedResource", as described in the section Example contentFiles section on the official documentation.
Below you can see my .nuspec file content:
<package>
<metadata>
<id>MyPackage</id>
<version>1.0.0.0</version>
<title>MyPackage</title>
<authors>Matias G Henschel</authors>
<owners>Matias G Henschel</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My package description</description>
<copyright>2017</copyright>
<contentFiles>
<files include="myDllFile.dll" buildAction="EmbeddedResource" />
</contentFiles>
</metadata>
<files>
<file src="content\myDllFile.dll" target="contentFiles" />
</files>
</package>
This package correctly copies the file inside the target project, but it doesn't apply the Build Action to it, which is crucial for me.
I've also tried using a .targets file, with no success.
If you want to see more, I've also created an Issue on the GitHub page.
PS: IMHO, both documentation on contentFiles and .targets files require some rework, they aren't clear enough and .targets' lacks examples.
You also need a file entry to actually copy the file to the correct contentFiles folder:
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
…
<contentFiles>
<files include="any/any/MyEmbeddedFile.txt" buildAction="EmbeddedResource" />
</contentFiles>
</metadata>
<files>
<file src="path/to/MyEmbeddedFile.txt" target="contentFiles/any/any/MyEmbeddedFile.txt" />
</files>
</package>
Note that this will only work in NuGet 3.3+ with project.json based projects and NuGet 4+ for PackageReference based projects. For projects using this package via packages.config, you will still need to add the file to the content folder and add a custom target to make it the right item type.

How to add additional files to a package using NuGet?

Attempt
Nuspec
<files>
<file src="https://raw.githubusercontent.com/030/chocolateyautomatic/master/common/Uninstall-ChocolateyZipPackage030.ps1" target="tools" />
</files>
Result
File is not added to tools directory
Running cpack indicates the following:
Calling 'C:\ProgramData\Chocolatey\chocolateyinstall\nuget.exe pack -NoPackageAnalysis
Attempting to build package from 'eclipse.nuspec'.
The given path's format is not supported.
Attempt two
<files>
<file src="path\to\chocolateyautomatic\common\Uninstall-ChocolateyZipPackage030.ps1" target="tools\Uninstall-ChocolateyZipPackage030.ps1" />
</files>
Result Two
The The given path's format is not supported. issue has been disappeared, but the Uninstall-ChocolateyZipPackage030.ps1 file is not added to the tools directory.
<files>
<file src="..\..\..\common\Uninstall-ChocolateyZipPackage030.ps1" target="tools\Uninstall-ChocolateyZipPackage030.ps1" />
<file src="tools\*" target="tools" />
</files>
adds all the files to the nupkg file.

NuGet package dll's + content files = fail?

I created a nuget package. I put some files and folders in a "content" folder and it worked great. So I added a bin folder with dll's and put this in my nuspec file :
<files>
src="bin\*.dll" target="lib" />
</files>
dll's are nicely put in the reference, but the content isn't copied anymore.
How can I manage to get them both working ?
#Edit
I know have this:
<file src="content\Controllers\*.*" target="Controllers" />
<file src="content\Views\Account\*.*" target = "Views\Account" />
<file src="bin\*.dll" target="lib" />
The package contains the right structure and files, but the files are not copied into my project.
The files are in a folder structure. When I put them directly into my content folder the are copied to the root of my project ...
When you define a files section in the nuspec we no longer do "automatic" / "Convention" based package creation. We see it as you are telling us what to include so we don't include things not in the list. Simply add the content folder to that list and it will work.
Edit to include comments from answerer's comment below
The NuSpec file "files" section tell NuGet where to put the files in the package not in sln/proj when it its unpacked. you want to write it like this:
<file src="content\Controllers*.*" target="content\Controllers" />
<file src="content\Views\Account*.*" target = "content\Views\Account" />
<file src="bin*.dll" target="lib" />