I have multiple .nuspec files generating similar but different packages. All of these .nuspec files that contains 95% the same content.
I want to have all the files that is used in all packages in a external xml file that gets included in the .nuspec and only unique files are then directly specified in the .nuspec.
My idea is something like below:
<files>
<!-- generic stuff -->
<include file="common.xml"/>
<!-- specific stuff -->
<file src="client1\*" target="config\data"/>
</files>
Where common.xml contains something like <file src="common\*" target="config\data"/>.
The above obviously does not work with nuget. I see nothing in the documentation that will get me there. Any ideas how to bend nuget to my will?
Related
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
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.
I have a nuspec template file (template.nuspec.pp) in the content folder of a Nuget package. When the package is installed, I modify the name of the nuspec file using an install.ps1 script to match the targeted assembly. I want the contents of the nuspec file to remain unchanged:
<?xml version="1.0"?>
<package>
<metadata>
<id>$rootnamespace$</id>
<version>$version$</version>
<title>$rootnamespace$</title>
<authors>$author$</authors>
<!--<iconUrl></iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$rootnamespace$</description>
<copyright>$copyright$</copyright>
<tags></tags>
</metadata>
</package>
The replacement tokens are replaced immediately on installation, however - I was under the impression this should happen only when nuget pack is called. Why is this happening, and what need I do to prevent it?
In case folks wonder, my install.ps1 file is not touching the contents of the nuspec template.
Looks like the whole point of the .pp suffix is to denote that any variable enclosed by $ is replaced on package install. When I removed the .pp suffix, the files were then ignored by Nuget and not added to the content folder. In order to circumvent this, I had to add a non .pp suffix to the file (I used .txt) and then renamed it using an install.ps1 script in my tools folder.
I am creating a NuGet package which requires a connection string, and would like to ensure it is added during installation. To this end I've created a config file transformation to add the string to a preexisting app.config, and a rule in my .nuspec to copy a prefabricated app.config into the project in case one doesn't exist.
Everything is working exactly as planned, however if the app.config exists I now see a "file conflict: overwrite?" dialog during installation. When this dialog appears the answer will always be no - the file will be edited by XDT if the app.config exists. Is there a way to suppress the dialog, defaulting to no? Alternatively: is there a better way to handle this?
You can recreate this by adding app.config.install.xdt and app.config files to a project's Content folder, and adding the following to your .nuspec:
<files>
<file src="Content\app.config.install.xdt" target="content" />
<file src="Content\app.config" target="content" />
</files>
I'm using NuGet tool in order to create a .nuspec using my .csproj.
The problem is always is generating me a file with a placeholders template:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
I don't know why is dumping me the same content.
Any ideas?
If you look at the NuGet source code this is how it is currently implemented. It always adds those place holders.
You are supposed to replace them.
There is no way for the nuget.exe spec command to determine what they should be and it adds placeholders for values that you probably want to specify.
not sure if you've already answered this yourself, but I was thinking the same thing. I had some values in my AssemblyInfo.cs file and was baffled about why they weren't being injected into the .nuspec file. I think we were expecting the same thing: running nuget spec or nuget pack [csproj file] would generate a new nuspec file with the parameters injected.
Turns out Matt is exactly right, it's just not how it works.
The key answer is that actually, the values are injected into the package. Later, when you try importing the package you will find that the values from AssemblyInfo are correctly injected, according to this table. (Note also that some elements are NOT injectable this way!)
Personally I find it somewhat baffling why they would do that, where the .nuspec sometimes contains literals that totally comprise the file, while other times contains templating that must be processed to produce another 'true' nuspec file (that is internal to the .pkg and can't be easily read, mind you).
Cheers!
I'm trying to automate creating a NuGet package to include .js files within my web project via Visual Studio 2013 when builds are run. I have done this using the NuGet Package Explorer but this needs to be automated.
I have used the Nuget package "CreateNewNuGetPackageFromProjectAfterEachBuild" and this seems close but the CreateNuGetPackage.ps1 script restricts to csproj files. Has anyone done this? I have searched and read that a powershell solution may be needed.
Does anyone know if this has been solved yet? At this point I'm ready to learn how to write a powershell script.
I suggest you to create proper nuspec file with wildchars like below:
<files>
<file src="bin\Debug\*.dll" target="lib" />
<file src="bin\Debug\*.pdb" target="lib" />
<file src="tools\**\*.*" exclude="**\*.log" />
</files>
and run just: nuget.exe pack yournuspec.nuspec