Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ship a nuget package with embedded pdbs #244

Closed
enzian opened this issue Feb 15, 2019 · 14 comments
Closed

How to ship a nuget package with embedded pdbs #244

enzian opened this issue Feb 15, 2019 · 14 comments

Comments

@enzian
Copy link

enzian commented Feb 15, 2019

I was wondering, what kinds of hoops I'd have to jump through to make this work?

I have a .csproj file like this:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <DebugType>Embedded</DebugType>
    <EmbedAllSources>True</EmbedAllSources>
  </PropertyGroup>

  <PropertyGroup>
    <PackageId>Some.Sample.Package</PackageId>
    ...
  </PropertyGroup>

but when using the nuget package built from this csproj using dotnet pack and I try stepping into an API, VS asks me where to get the source file... Isn't that supposed to be embedded?

@tmat
Copy link
Member

tmat commented Feb 15, 2019

Yes, the sources should be embedded. What VS version do you use? Can you share the package?

@jjpepper
Copy link

Isn't it also necessary to include:

<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>

In the top PropertyGroup?

@enzian
Copy link
Author

enzian commented Feb 18, 2019

@tmat : I'm running VS 15.9.7 i do have a package on NuGet id is not sourcelinked yet. I was trying it out with a local package feed but that did not work so far! I'll drop a line here, when I have uploaded the package!

@enzian
Copy link
Author

enzian commented Feb 18, 2019

ok I published the nuget package from this repository. This is the release and there is an artifact for the nuget package as well!

@tmat
Copy link
Member

tmat commented Feb 19, 2019

Isn't it also necessary to include:
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
In the top PropertyGroup?

It is not. The project sets DebugType to embedded, which means the PDB is going to be embedded to the DLL. Furthermore, the project also sets EmbedAllSources meaning the sources are going to be embedded into the PDB. This approach is the best when the resulting size of the DLL is not an issue, as the debugger doesn't need to find the PDB on a symbol server and the sources on the source server. Everything is embedded in a single file (the DLL).

@tmat
Copy link
Member

tmat commented Feb 19, 2019

@enzian

I'm running VS 15.9.7 i do have a package on NuGet id is not sourcelinked yet. I was trying it out with a local package feed but that did not work so far! I'll drop a line here, when I have uploaded the package!

SourceLink is not needed as you're embedding sources into the PDB. SourceLink is only useful when linking the PDB to sources on a source server.

@tmat
Copy link
Member

tmat commented Feb 19, 2019

@enzian I tried to step into a method in your library and everything seems to work fine in VS 15.9.5.

This is what I tried:

  1. Create a console app targeting .NET Framework or .NET Core and add reference:
  <ItemGroup>
    <Reference Include="c:\temp\Microsoft.Extensions.Hosting.Kafka.dll"/>
  </ItemGroup>
  1. Place breakpoint to the Main of the app as indicated:
using Microsoft.Extensions.Hosting.Kafka;

class Program
{
    static void Main()
    {
        var s = new KafkaListenerSettings();
        s.DefaultTopicConfig = null; // breakpoint
    }
}
  1. F5. When the breakpoint is hit, select from editor context menu:
    image

  2. The debugger navigates to the source:
    image

Note that "Just My Code" in the Debugger options must be enabled in order for the above to work.

@enzian
Copy link
Author

enzian commented Feb 20, 2019

Oh, actually, when I used "Step into specific" to step into the library methods then it asked me to disable "Just my Code" and then it worked! Cool!

@enzian enzian closed this as completed Feb 20, 2019
@mikebeaton
Copy link

mikebeaton commented Jan 21, 2020

I found this thread very helpful, but I'm confused - I don't know if anybody has time to help.

From my experience with trying to set up SourceLink on my own packages, I have found that:

  • <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> simply does not work: the consuming Visual Studio never finds the PDB and never loads the symbols, even though yes, the PDB is in there next to the DLL in the NuGet file (and if I copy out that PDB using a zip manager and shove it into the compiled directory, it works)

One the other hand:

  • <DebugType>Embedded</DebugType> (as used by enzian in his helpful tests above) works fine, straight away!

What am I missing? Why do all the tutorials use something which apparently doesn't work?!

[EDIT: Okay, I think I'm hitting this issue: https://github.com/dotnet/sdk/issues/1458 ]

@tmat
Copy link
Member

tmat commented Jan 21, 2020

That's right. The SDK unfortunately doesn't copy the PDB as detailed in dotnet/sdk#1458.

@tmat
Copy link
Member

tmat commented Jan 21, 2020

@mikebeaton Any reason not to publish PDBs via symbol packages (snupkg)?

@mikebeaton
Copy link

@tmat I'm trying to set this up on a private NuGet feed, and as far as I can make out neither the file system based feed nor the Microsoft NuGet.Server IIS package have symbol servers or support .snupkg files?

@tmat
Copy link
Member

tmat commented Jan 21, 2020

@anangaur @rrelyea

@anangaur
Copy link

@tmat Can you open a NuGet issue and link it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants