El MoZo
El MoZo

Reputation: 157

Show source code of my nuget

My team and I build our own Framework we use in many project. We used to include the framework's project in all our others projects but then we decided to put our Framework into a nuget package host on our nuget server so we can had versioning and spread our framework more easily during our developments.

Every-things is working fine except but there are some notable sides effects to this.

Visual studio is not able to look directly into the nuget's dll itself, so for example the VS search engine can't look for function that are present in my nuget. For the same reason I assume, I can't see the source code of our framework in my project anymore, only the metadata are shown.

I understand it's a normal behavior for a nuget package to not show it's own source code but I would like to know if it's possible to set nuget package to a "trusted mode", so that visual studio will be able to search for function inside it and developpers able to look directly at the source code (without being able to edit it of course).

Thx a lot.

Upvotes: 5

Views: 5671

Answers (1)

Leo Liu
Leo Liu

Reputation: 76720

so that visual studio will be able to search for function inside it and developpers able to look directly at the source code (without being able to edit it of course).

If I aware of you correct, you want to access the code in the nuget package but could not edit? If yes, you can try to create symbol packages which allow consumers to step into your package code in the Visual Studio debugger.

The way we do it (and works):

  1. Create "*.symbols.nupkg".

  2. Deploy symbol package to SymbolSource server.

  3. Configure IDE, Package consumers can add https://nuget.smbsrc.net/ to your symbol sources in Visual Studio.

  4. Add required Library to project using NuGet (from our SymbolSource server). Debug.

For the detail info, you can refer to Creating symbol packages.

If these packages are not suitable for publishing on NuGet Gallery/SymbolSource, you can put the *.nupkg and *.symbols.nupkg files on a NuGet local feed on a network share. For the detail for this method, you can refer to the similar issue:

Is it possible to host both regular and symbols packages in a NuGet local feed on a network share?

Besides, in this condition, you do not have to worry about developers going to edit the source code, because all packages are downloaded to local packages folder, edit would not affect the source code on network share until you re-publish it.

Update Detail:

You should add a breakpoint and press F11 to step into the source code:

enter image description here

Update check the source code in dll by F12:

According to the MSDN documentation

The debugger looks for source files in the following locations:

>1. Files that are open in the IDE of the Visual Studio instance that launched the debugger.

>2. Files in the solution that is open in the VS instance.

>3. Directories that are specified in the "Common Properties" / "Debug Source Files" page in the properties of the solution.

>4. The source information of the .pdb of the module. This can be the location of the source file when the module was built, or it can be a command to a source server.

So if you want to access the source code in dll file by F12 directly, you should add the source code in the solution. You can create a new project in the solution to house the source files and add this project as reference project. This will clutter up your solution/project, but since it will be checked into source control, all team members will automatically be able to debug into the source files.

Besides, ReSharper should be recommended, you can enable it by going to ReSharper / Options / External Sources, and move up "Sources from symbol files". Then in the tab "Sources from symbol files", click "Advanced" and there you can map source folders.

Upvotes: 6

Related Questions