1

I have a few functions I want to make available to many projects I'm working on. So naturally I thought I should make a NuGet package to contain the shared code. so I:

  1. Created a class library (in this case called ADUserCacheUsage).
  2. Fixed the Assembly Info for that class library.
  3. went to the directory with ADUserCacheUsage.csproj, and in a command window did nuget spec. This generated a .nuspec file.
  4. Fixed that nuspec file for my project.
  5. nuget pack ADUserCacheUsage.csproj -Build -Symbols -Properties Configuration=Release (after all, if someone externally is using the package, they only need the release build, right?)
  6. nuget add ADUserCacheUsage.1.0.0.nupkg -source "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages"

So great, my NuGet package shows up when I select the machine source in the package manager. So I can use it in my projects.

I'm making a sample web page to use it. All the sample does is call one function and output the result on a web page.

The problem is, whenever I try and run this sample project in debug mode, I get the warning message

You are debugging a Release build of ADUserCacheUsage.dll.

So presumably I should be including a debug version of my class library in my package, in addition to the release version, right? I wouldn't want the final release of the sample project to bother with the debugging information, potentially being slow and bloated (admittedly not much of an issue on a project that's just a sample, but I'm thinking for best practices and in the future where I might have a larger, more complex package).

But I want to be able to run in debug without this error. Whenever I make a web project, it includes many other projects, and it never gives me this error with regard to, for example, NewtonSoft.json. So what should I be doing in order to do this the right way? Does every package on nuget.org just include the debug version?

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Adam R. Grey
  • 1,861
  • 17
  • 30
  • First many packages do not include symbols (e.g. Newtonsoft.Json). Second, this is probably only an issue on the machine where you built the dlls because the debugger is able to find the source files from the information in the pdbs. On another machine without the source code, you would not be able to debug into the library. – Mike Zboray Feb 06 '18 at 22:16
  • 1
    You're specifying Release as your build configuration. Change it to Debug and the PDB will be included – Josh E Feb 06 '18 at 22:21
  • But *should* I specify the debug build? Are all the packages on nuget.org distributing their debug build? – Adam R. Grey Feb 07 '18 at 14:33
  • AFAIK, the most of packages on the nuget.org do not distributing their debug build, because it does not make much sense, A NuGet package will normally hold just a single set of assemblies for a particular target framework. It is not really designed to ship a debug and release version. Please check this thread: https://stackoverflow.com/questions/36053961/debug-and-release-nuget-packages-local-repository and https://stackoverflow.com/questions/47799179/custom-nuget-package-with-configuration-framework/47807794#47807794 for details. So what NightOwl888 said is right. – Leo Liu Feb 08 '18 at 02:15
  • @LeoLiu-MSFT As I thought. So I specify the release configuration. But then we're back to my original problem: I'm getting an error message that says I'm trying to debug a release dll, but it only happens for my package. – Adam R. Grey Feb 08 '18 at 13:25
  • @Adam R. Grey, Disable/Enable Suppress JIT optimization on module load (Managed only) under Tools->Options->Debugging. View the result in your side. – Leo Liu Feb 21 '18 at 08:03
  • @LeoLiu-MSFT ok, it was disabled, I enabled it and the warning went away. But that doesn't explain why the warning only showed up for my package, never for anything else. If I wanted to build and distribute a package, I'd have to give them the extra step of doing this. – Adam R. Grey Feb 21 '18 at 16:03

2 Answers2

0

NuGet packages don't contain debug information.

Instead, there are separate NuGet symbol packages (ending with .symbols.nupkg) that contain debug symbols (.pdb files) and the source code files. Symbol packages can be created using either the nuget pack -Symbols or dotnet pack --include-symbols command tools.

After the symbols packages are created and hosted (either on a symbol server or on the local file system), you can configure Visual Studio to use them to step through the code, even though the code in the NuGet package was built using Release mode.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • So if you don't specify `-Properties Configuration=Release`, it will still make a release build but it just won't trigger the error message? – Adam R. Grey Feb 07 '18 at 14:50
  • @NightOwl888 yeah that's what I meant, from nuget.org, symbols are pushed to a different server that host symbols (the .snupkg). But if you use a local feed you will either have to rebuild your own local symbols server (don't even know if that's possible) or find a way to configure vs to find those symbols. Adam R. Grey wanted to know why he had this error with its packages only. The answer is probably because its release packages was configured with portable where ha should have released them with none if he don't have a local symbol server. – Erhode Apr 22 '23 at 10:42
0

Hey I just ran into the exact same issue and didn't find any satisfying answer on forums. I managed to understand what's going on some I'm posting the solution that worked for me and I'm pretty confident that the problem you faced was the same as me.

What I understand is that visual studio displays this warning if you try to debug a library that is "tagged" as one that can be stepped into. Even if publish your nuget in release, with code optimization checked, if symbolic links has been produced for it, the dll has internal flags saying that symbolic links exists and therefore can be debugged. Then, if it can't find the pdb files (which has far as I know isn't possible with local packages, even if you include the pdb in the packages) you will get this warning.

For packages produced in nuget.org in release, those symbols are published into a symble server as .snupkg.

Now the solution: If you go to the build options of the project your are building you should have something like this:

Default build options

This means Code optimization will be applied only for release configuration but pdb files will be produced for all your configurations.

cog options

By clicking the cog options, you will see the default value checked "Use the same value among all configurations".

By selecting instead "Vary value by configuration" you will know have the list of your configuration listed and you can remove the symbols generation for your Release configuration or the one you are using for your nuget package.

no pdb for release

Now packages created in Release won't cause the "Just my code warning" when you start in Debug an app that reference them!

I'm using vs 2022 and it looks like your where on vs 2015. So the interface might have change a lot but applying this configuration add those two lines on the .csproj.

csproj

No matter your vs version I'm pretty confident that you can just directly add those two lines into your csproj and achieve the same result.

Erhode
  • 152
  • 8