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.
Related
NuGet nuspec files allow you to specify the target for <file> elements.
eg.
<files>
<file src="things/**/*" target="content/stuff/" />
</files>
Is there an equivalent if you're using a csproj (and dotnet pack), instead of a .nuspec file?
eg. Given
<ItemGroup>
<Content Include="things/**/*" />
</ItemGroup>
Can I add something to that to make those files end up in content/stuff in the .nupkg file?
According to the Microsoft docs, I'd say it should look like this:
<Content Include="things/**/*">
<Pack>true</Pack>
<PackagePath>content/stuff/</PackagePath>
</Content>
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.
I am creating a nuget package definition to include a whole bunch of DLLs. Some of them are needed only at design time, so according to the Nuspec Reference I created a references section to specify which assemblies should be referenced by the project.
I also specified a list of files to be included. Some of these files being the libraries, one is a PowerShell script that gets executed during package installation and one is simply a content file that should be added to the project lateron.
These are the relevant sections of my nuspec file:
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<!-- Most of the metadata stuff left out for brevity -->
<dependencies />
<references>
<reference file="MyComponent.dll" />
<reference file="MyComponent.Data.dll" />
<reference file="MyComponent.Other.dll" />
</references>
</metadata>
<files>
<file src="MyPackage.install.ps1" target="tools\install.ps1" />
<file src="MyComponent.ReadMe.txt" target="ReadMe.txt" />
<file src="C:\Some\Path\MyComponent.*.dll" target="lib\net45" />
<file src="C:\Some\Path\MyComponent.*.xml" target="lib\net45" />
<file src="C:\Some\Other\Path\*.dll" target="lib\net45" />
</files>
</package>
Now here is my problem: The licenses.licx file does not get included in the project when the package is being installed. What must I change to achieve this?
Adding it to the references section does not work, because, well, it is no library...
I found out what was wrong. To include a file into the targeted project the file needs to be placed in a sub-folder named content in the package's folder structure:
The correct files section of the nuspec file would then look like this:
<files>
<!-- other files omitted for brevity -->
<file src="MyComponent.ReadMe.txt" target="content\ReadMe.txt" />
</files>
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.
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" />