2

I have a visual studio .net core api that references a artifactory based nuget package within my solution. The nuget package is a .net core class library. On my local I have both solutions the main API solution and the class library solution. What I am trying to accomplish is I want to be able to run the API in debug mode and break into the method call in the class library code I have local with little too no changes at all if its even possible without changing references around etc. in the API. Trying to avoid having to disable the nuget package and reference the local project file in the solution etc.

Is there anyway to accomplish this? What I tried was I start up the API solution in debug mode then I go into the class library project 'Attach to Process' and pick the 'devenv.exe' that is in debug. I also tried like publishing the DLL and PDB file to the same debug folder as the API but still does not break into the code.

Any suggestions is there a way to handle this local? Hope this makes sense.

beantownace
  • 117
  • 1
  • 10
  • I'm a little confused by the wording. Do you have access to the source code of the NuGet package? (i.e. can you go in and view the full files that are then compiled into the NuGet package?) – Chris S Jul 16 '20 at 00:19
  • Yes Chris correct I have the full code of the Nuget solution. I have the nuget solution which is the .net core class library that is used for code to git hub then the code goes through ci/cd and published to Artifactory. In an API solution I have locally I manage nuget packages and that has a reference to the Artifactory nuget package. I need to however debug that class library nuget package and step into the class library code. Trying to avoid having to change the API solution to reference bringing in the class library project and changing the API code to reference the local project – beantownace Jul 16 '20 at 00:33
  • I am trying to see if there is a way to attach to process somehow the class library to the API and debug that way. – beantownace Jul 16 '20 at 00:34
  • https://learn.microsoft.com/en-us/nuget/create-packages/symbol-packages-snupkg – Lex Li Jul 16 '20 at 00:55
  • so how would I use that locally for my case Lex? I know that can publish the package symbols. – beantownace Jul 16 '20 at 01:01
  • @beantownace, any update for this issue? Please check if my answer helps you handle this issue? If it helps, please do not forget to [accept it](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). If you have any other concern or problems, please feel free to let us know. – Mr Qian Jul 22 '20 at 06:14
  • @beantownace, please try to check if my answer helps you handle the issue:) – Mr Qian Jul 23 '20 at 09:49

1 Answers1

1

Debugging Nuget Package locally

To debug a nuget locally, you should need the pdb file and compile files(cs resource files) and then you can debug the nuget with both of them. It is quite different from the server.

To pack it, you can pack the xxx.pdb as lib and pack cs files in the nupkg file. So both of them will restore in the nuget packages.

In your net core class library project, use these:

<ItemGroup>
    <None Include="$(OutputPath)ClassLibrary.pdb" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
 <Compile Update="Class1.cs" Pack="true"  PackagePath="Resource">
</ItemGroup>

Then, the cs files will exist under Resource folder and the pdb file will exist under lib folder.

enter image description here

========================

Then, install that package in a main project, right-click on the main solution-->Properties-->Common Properties-->Debug Source Files-->to add the folder path which the cs files exist into it(unpack the package and add the path if Resource folder ) .

And then you can debug the nuget package locally.

In addition, you can also refer to this similar thread which I explained before.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41