NuGet exclude files from symbols package in nuspec - nuget

When doing a nuget pack against a .csproj file that has an accompanying .nuspec file, what is the syntax for excluding certain files from the symbols .nupkg?
For clarity, I do not want to exclude these files from the normal .nupkg, just from the symbols .nupkg. This is because SymbolSource fails to parse these files as managed assemblies.
Our workaround is to remove specific files from the symbols .nupkg after it has been created but it would be preferable to exclude them in some declarative fashion in either the .nuspec file or else in the package command.

This might be abit of hack, but you could something like this:
nuget pack mypackage.nuspec -Symbols -Exclude "*/*.exe;*/*.dll"
Where "*/*.exe;*/*.dll" are the files you want to ignore and then run
nuget pack mypackage.nuspec
Where your mypackage.nuspec includes everything that you want in your regular nuget package.
This shouldn't cause any problems, since the dll, pdb and nuget packages should still have all matching versions.

Related

Error NU5012 - nuget pack unable to find path (/bin/release/MyProject/bin/release)

I'm trying to update my nuget package by running the command nuget pack -properties Configuration=Release but this gives me the following error:
Unable to find 'bin/Release/{project-name}/bin/Release'. Mae sure the project has been built
I'm not quite sure why it goes to my Release folder and then continues to go down to another Release folder as this doesn't exist? I'm quite lost here, and I'm not sure what to do.
TL;DR
For the new <Project Sdk="Microsoft.NET.Sdk"> .csproj file format, use dotnet pack to build NuGet packages, even if they target .Net Framework or if the project is multi-targeted. Run this from the directory containing your .csproj (and optionally a .nuspec)
dotnet pack MyProject.csproj -c Release
Note that by default dotnet pack places the output .nupkg in the /bin/Release folder, which is different from the current default folder where older nuget pack placed it.
I would suggest you don't create explicit .nuspec files for the new .csproj formats, since most settings can be set in the "Packages" tab of the new Project format. However, if you do have a .nuspec, then dotnet pack will also combine any .nuspec file matching the project name, allowing for the $ symbol substitution from the version and metadata set in your .csproj.
More Detail
I also experienced this problem - in previous versions, I typically use to use this approach to pack against a .csproj with the .nuspec file of the same name, so that I can use all of the $ tokens like $id$, $version$.
However when attempting this against the newer <Project Sdk="Microsoft.NET.Sdk"> csproj formats:
nuget pack {MyProject}.csproj -Prop Configuration=Release
I received the same error (note the "duplication" of bin\release):
Error NU5012: Unable to find 'bin\Release{MyProject}\bin\Release\'. Make sure the project has been built.
And if I tried packing against a .nuspec containing symbols (NuGet Version: 4.7.1.5393)
nuget pack {MyProject}.nuspec -Prop Configuration=Release
I just get the unhelpful message because nuget isn't able to resolve the $ tokens automatically.
Value cannot be null or an empty string.
Parameter name: value
However, by using dotnet pack instead of nuget
dotnet pack MyProject.csproj -c Release
I get to where I want to be, i.e. a multi-targeted NuGet package with the $ symbols in the .nuspec correctly synchronized from the .csproj (you can verify this by opening up the .nupkg file in e.g. 7zip and examining the final .nuspec file in the package root)
I had the same problem on a multi-targeted project (targetting both net452 and netstandard2.0).
My fix/hack was to add 'TargetFramework=net452' to the list of properties passed to Nuget, and manually adding the netstandard2.0-output to the files-section in the .nuspec-file
Hope someone finds a better solution
Part of Rune's answer (setting TargetFramework=net471 NuGet property)
and using NuGet version 4.9.1 (instruction here: https://stackoverflow.com/a/53614798/1813219)
was a way to go for me.
Actually I just solved the problem on my end. Nuget may not find hidden dll. Here is my solution:
Build the project;
Show all files in visual studio so you can see the hidden files, so that you can see the dll under bin folder;
Right click, open folder in file explorer, then copy it to current folder let them replace/ Or unhidden the files;
Do "Nuget Pack" again.

How does NuGet decide which files are included when packing a csproj file?

I'm trying to use the simplest and most automated approach possible to create a few NuGet packages from some of our projects, by using the nuget pack [path-to-csproj] method.
For most of the projects I've tried this, the command line tool seems to understand the .Net framework version of the projects and it adds the output dll and xml files to the correct lib folder. In some other project, it is including a .css file to the content folder in the package, I assume because the file has a Content build action.
What exactly does this NuGet command include in the final package and how does it extract this information? Is there a comprehensive documentation on the file extraction from the csproj? I'd like to understand this process so that I can hopefully add my own files to it, like the app.config file and some code contracts assembly files without having to hardcode paths in the nuspec definition.

nuget pack with symbols is missing "content" directory

I'm using nuget to package up some assemblies and additional files.
I need to keep the symbols separate, so I'm using "nuget pack -symbols" which creates two separate nupkg files.
The problem I have is that the .symbols.nupkg package only contains the "lib" directory (with PDBs and DLLs). It is missing "tools" and "content".
This means when someone installs the .symbols.nupkg, they don't get the extra files underneath "content". And because .symbols.nupkg has the exact same package id as the main .nupkg, nuget won't ever install the main package which does have "content" in it.
It's the same nuspec file which creates both packages, so I can't control it there.
Am I doing something wrong, or misunderstanding how the symbols package should be used?
The problem is - *.symbols.pckg are meant to be kept on www.symbolsource.org ( or a local symbols feed)
Sumbols.pckg does not replace a real package. It's an addon.
Publish your package to nuget feed and symbol package to symbols feed.
But you actually can include pdb files in packet. Add this to nuspec file
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net45\" />
</files>

NuGet.exe not packing directories that start with dot

I am using NuGet.exe to pack up a directory of files and it seems that it ignores any directory that starts with a dot. Even when I try to explicitly use the "files" entry in the nuspec file, it won't let me include that directory or any of the files within it.
Is there a way to override this behavior?
Here is my command line:
NuGet.exe pack ..\build\MyPackage.nuspec -OutputDirectory "\someserver\blah" -basePath "c:\temp\packageStaging" -Version "3.0" -NoPackageAnalysis
The reason for NoPackageAnalysis is that I am making a non standard package for use in Octopus deploy.
you could use -NoDefaultExcludes option of nuget.exe
more details here: http://docs.nuget.org/docs/reference/command-line-reference
NoDefaultExcludes Prevent default exclusion of NuGet package files and files and folders starting with a dot e.g. .svn.
I know this is an old thread, but I had same problem today, the directory ".well-known" was not added to the nupkg-file.
I solved it by removing the "dot" in the directory name to and added a "target" in the nuspec file:
<file src="well-known\**" target="./.well-known/"/>

Is there a way to specify Build Action=None with nuspec?

My company has an assembly versioning package that I've written in powershell and is distributed amongst my colleagues via our internal nuget feed.
There are a couple of template files which can be user-modified after the package in installed. These files are being included in the package which we generate via
nuget pack xxxx.csproj
We've done a little investigation and there files are not packaged when we change the Build Action to None.
Is there a way to tell nuspec to add the files to the project with Build Action set to None*?
Alternatively is there a way to tell nuget pack to not include certain files in the package in generates?
NuGet pack has an Exclude parameter that can be used to filter out files that you don't want in your package.
If you want to include files that are auto excluded from your project then you need to add a nuspec to your project and add a element that includes that file.
More information here:
http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_project
http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command
nuget pack will ignore any files or folders that start with period/full stop. So one easy way would be to rename your template files or the folder they are located in to start with a period/full stop if possible.