nuget pack with symbols is missing "content" directory - nuget

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>

Related

Nuget .symbols.package upon install doesn't contain pdb's and installs only dll's- VS 2019

I have nuget package with symbols - "Mypackage.symbols.nuget" and has dll and pdb files.
I created a local repository for testing and installed this "Mypackage.symbols.nuget" but after installing i see only dll file present in nuget folder under users directory and pdb is missing.
i tried a tweak by renaming the file manually to "Mypackage.nuget" from "Mypackage.symbols.nuget" and then i tried to install i see both dll and pdb is present after i installed.
Why does not pdb is getting downloaded when i have .symbols.nuget as i need to symbols package with dll and pdb for debugging purpose.
i created nuget package upon csproj property group.
Please suggest.
Mypackage.symbols.nuget is not a package in the form of being installed, and does not have the conditions for being installed. The purpose of this form of package is to publish to nuget.org together with nuget.nupkg. Usually, you should push the Mypackage.symbols.nupkg file into https://nuget.smbsrc.net/.
Before this, you should also push the Mypackage.nupkg into nuget.org(https://api.nuget.org/v3/index.json).
And then input the symbolsource.org(https://nuget.smbsrc.net/) into VS Symbol Server.
In this case, you could install the published Mypackage.nupkg package from the nuget.org and then it will match the related Mypackage.symbols.nupkg on the symbolsource.org so that you can debug the content of the nuget.
You can refer to this document about creating legacy symbol packages(.symbols.nupkg).
=============================================================
All of the above need to push these packages into nuget.org. And in the local, you should use that way. And Mypackage.symbols.nupkg is not an installed package for any projects.
To prove this, you can try these:
1) in my side, I add these node in csproj file to create the symbol package.
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>
Then, config the local path of it into nuget package source. After that, delete the xxx.nupkg directly,
I am sure that nuget package UI cannot find the package under the local path which proves the Mypackage.symbols.nupkg is not an installed nuget package and only be uploaded into the server.
Solution
1) just rename the Mypackage.symbols.nupkg as Mypackage.nupkg since it has the dll and pdb files.
2) use this csproj node to repack your project.
<ItemGroup>
<None Include="$(OutputPath)$(AssemblyName).pdb" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
</ItemGroup>
And the main xxx.nupkg will contain the pdb file.
3) also use this xml node in csproj file:
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
Note: if you want to debug the nuget package locally, you should also pack the resource files into the nupkg file.
See this thread answered by me.
In addition, using Debugging information: Embedded format might be much easier.

Suppress warning output from Nuget.exe

I'm wondering if I can suppress warning messages in the output from the nuget.exe pack command? Specific messages would be awesome, but I can live with suppressing all of them.
The nuget command line documentation mentions a Verbosity flag, but never really specifies what the valid values for that are. I've tried the following:
nuget pack mypackage.nuspec -Verbosity Quiet
But doesn't seem to do anything.
Here is an example of the nuspec I'm trying to pack:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>1.0.0</version>
<authors>Administrator</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My package description.</description>
</metadata>
<files>
<file src="mysourcepath\foo.dll" target="mytargetpath\foo.dll" />
</files>
</package>
The warning message I get is this:
WARNING: 1 issue(s) found with package 'MyPackage'.
Issue: Assembly outside lib folder.
Description: The assembly 'mytargetpath\foo.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project.
Solution: Move it into the 'lib' folder if it should be referenced.
I'm creating a nuget package that will be deployed as an application via an Octopus server. The assemblies in this dll do NOT need to be referenced by anything - this package should never be referenced as part of a build (we have other more logical packages for that).
I want to suppress this warning because the actual package I'm creating has thousands of files, none of which are in the lib folder. The output noise from this one warning is making it difficult to see any other legitimate warnings I might be interested in.
UPDATE: This package is packed from a custom nuspec file - it consists of the output of hundreds of projects, so specifying a project file is not a viable option for eliminating the warning. FWIW, specifying a project file does eliminate the warning, because it ends up putting the project output into a lib folder - which is what I'm trying to avoid.
TIA for any input.
First of all, nuget reference clearly specifies what the valid values are for Verbosity.In the link you have provided under the pack command section:
Display this amount of details in the output: normal, quiet, (v2.5) detailed.
Try packing your project file instead of .nuspec file if possible, use lowercase for quiet flag and use -NoPackageAnalysis:
nuget pack myproject.proj -Verbosity quiet -NoPackageAnalysis
The -nopackageanalysis flag will suppress the warning, even when using a .nuspec file.
You might also consider using Octopack, if it's an option. Octopack was designed to create packages specifically for Octopus Deploy (i.e., no lib folder, no spurious warning messages, etc.) It uses NuGet under the hood so you can still use it with a .nuspec file as well.
You can pass specific properties into the NuGet CLI, including "NoWarn":
nuget.exe pack package.nuspec -Properties NoWarn=NU5104
https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#suppressing-pack-warnings

Install specific dlls from nuget package

I have a .sln package named MySolution. In that Package I have some dlls, like:
MySolution.sln
\one.dll
\second.dll
\another.dll
I want to install only specific dll to my another Project, so they will add as reference to my Project. I m trying to install like
PM> Install-Package MySolution
In that way all dlls added to my Project, but I only want some of dlls like one.dll and second.dll thats it.
Is there any way to do this?
Your options are:
Add the .dlls you do not want as assembly references as Content files.
<file src="lib\Net40\another.dll" target="content" />
This will add the .dll as a file to the project.
Add the .dlls you do not want as assembly references as Tools files.
<file src="lib\Net40\another.dll" target="tools" />
The tools directory is one of the sub directories where your package is extracted to.
Then use PowerShell to put the files into the location you need them in the project.
Or alternatively you could write a custom MSBuild target file which references the files from the tools directory. Your MSBuild target file is a just an MSBuild file where you can define properties and files just like a standard MSBuild project file. So you can reference the .dlls in the tools directory and have them copied to the output directory.

NuGet exclude files from symbols package in nuspec

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.

Create nuget package with multiple DLLs

Let's say I have a project with this structure:
MyLibrary\
MyLibrary.sln
MyLibrary.Core\
MyLibrary.Core.csproj
MyLibrary.Extensions\
MyLibrary.Extensions.csproj
MyLibrary.Tests\
MyLibrary.Tests.csproj
I want to create a single NuGet package which packages MyLibrary.Core.dll and MyLibrary.Extensions.dll. I can't seem to figure out how to get NuGet to do this. I've tried building a spec file manually and I've tried building one using "nuget spec MyLibrary.Core.csproj". I've tried adding all of the DLLs to a lib/ folder which I understand to be the convention-based mechanism for adding DLLs to the package. In every case I can get the MyLibary.Core.dll to get into the package but the MyLibrary.Extensions.dll does not end up packaged along with it.
TLDR: What is the best practice for creating a NuGet package with multiple projects / assemblies? Is there a tutorial out there that focuses on this? The tutorials I've found all focus on simple single-project demos.
You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element. This element uses the names of your project's References, so you avoid having to a) find the location of other project files, and b) copy files to a particular place as a post-build step.
Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
</metadata>
<files>
<file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" />
<file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" />
</files>
</package>
With this setup, all of your references should end up in the appropriate place in the NuGet package. You still have the hard-coded 'Release' in there, but I'd wager most probably don't distribute NuGet packages of their debug builds anyway.
Did you generate a blank nuspec file with:
nuget spec
If you use that file and then put your dlls in a folder under it named lib, it will package them up.
I had a little trouble with trying to generate a nuspec file from a project or dll. Also, if you manually reference any files in the nuspec file, the conventions are not used. This is probably the problem with nuspecs generated from dlls or projects.
Also, if you are trying to run this from a build script that executes in a different folder, you can tell nuget the location of your .\lib folder via the -BasePath command line:
build\nuget.exe pack nuget\Company.Project.nuspec -BasePath nuget\
Have you tried NuGet Package Explorer? Might be the easiest way:
http://nuget.codeplex.com/releases/view/59864
It seems your problem is the same as this question: Why doesn't nuget include the referenced project when packing?. If so, you can use the -includereferencedprojects option (See http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command).
I recently published a solution for this...
My solution enables automatic creation of NuGet packages when you build the solution where each package can contain multiple assemblies, references to both external NuGets and NuGets created during the same build and even include the source code for debugging.
In your case, all you will need to do is add a new class library project to your solution, reference the projects you want to package, then add a post build event.
You can find an article with a walk-through guide here
and the source code here.
i have some tutorial how i did it with windows and visual studio:
create local folder and call it packages like: c:/packages//lib - important to create another folder in folder call it lib and past there dll.
open nuget package explorer - https://npe.codeplex.com/downloads/get/clickOnce/NuGetPackageExplorer.application
the ui very intuitive just add dll and export it to /lib (for tutorial https://blog.zwezdin.com/2014/building-nuget-packages-with-gui-tool/ it in russian but see on pictures the flow it's about 3 clicks)
it will create nuspec file
open GIT BASH - https://git-for-windows.github.io/ and navigate to: cd c: => cd packages (the path of )
*maybe on windows you will need provide developer options for windows's linux stuff (https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/)
in GIT BASH enter command: nuget add -source [options]
where: : the full name of nuspec (include .nuspec)
and: the path of folder lib in folder (c:/packages//lib)
after the action ended successfully
in GIT BASH enter another command:
nuget pack .nuspec
not in this folder you have .nupkg file.
How to install a Nuget Package .nupkg file locally? - tutorial how to add it to visual studio.
I had the same problem and I decided to create Nuget which will allow to create other nugets from chosen project.
Package is deployed on the Nuget.org site. After referencing it in the project You need to add nuspeck file to the projects which should generate the projects.
Project with the required nuspeck file
Last thing which should be done by you is invoke command Create-Nuspec in Package Manager. Than the powershell module will take all libraries which are result of the build it will add also the required dependencies and create the nuget in the output directory.
Description about this package is placed here.
I had an issue when adding extra dlls references to a Nuget packages, and testing the package on a sample project, the extra dlls was not being added apparently, no matter the way that I create the Nuget Package.
Then I released that when you uninstall and install again a local Nuget Package with the same version number the changes no take effect, the extra dlls are not added.
So each time you uninstall the package, close visual studio and clear the Nuget Cache,
How to clear NuGet package cache using command line?
Then open again Visual Studio and reinstall the local package to make the change takes effect.
Or make the package version to increase each time to be for Visual Studio to recognize your changes.
For example:
Package-1.0.0
Package-1.0.1
Package-1.0.2
.....
To create a Nuget package from a sample project there are some ways, for example:
Right click to your Visual Studio project and choose the "Pack" option
Then install the nuget package explorer:
https://www.microsoft.com/es-ec/p/nuget-package-explorer/9wzdncrdmdm3?activetab=pivot:overviewtab
And add manually your extra references (dlls files) to your specific targets.
Create a nuget package using a .nuspec file how specified in the documentation:
https://learn.microsoft.com/en-us/nuget/guides/create-packages-for-xamarin
<files>
<file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.dll" target="lib\netstandard1.4\Plugin.LoggingLibrary.dll" />
<file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.xml" target="lib\netstandard1.4\Plugin.LoggingLibrary.xml" />
<file src="Plugin.LoggingLibrary.iOS\bin\Release\iOsDependence.dll" target="lib\Xamarin.iOS10\iOsDependence.dll" />
<file src="Plugin.LoggingLibrary.Android\bin\Release\AndroidDependence.dll" target="lib\MonoAndroid10\AndroidDependence.dll" />
</files>
In your files part add your .dll files.
And dont forget, each time you uninstall and install again the nuget package from your local source.
Or you increase the version of the package each time:
Or close Visual Studio, clean the nuget cache and Rebuild your project.
In order to take effect the changes.