5

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.

El MoZo
  • 157
  • 1
  • 10

1 Answers1

6

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks for your answer Leo. Following your second link I'm able to debug by manualy adding src to the 'debug source files' of my solution like described in point 2 of the answer. But the problem remain the same. Outside being actually debugging my code, I don't have access to source code (only metadata) and the can't search with the VS engine for a function in my package. Will this be the same with a SymbolSource Server ? – El MoZo Aug 23 '17 at 08:13
  • @ElMoZo, I have created a sample and it works fine on my side. Do you mean that you could not step into the source code? Have you try to use project reference instead of nuget so that you can make sure you can step into your source code. I have updated my answer with a simple jpg file, you can check it for detail. – Leo Liu Aug 23 '17 at 09:21
  • I'm able to step into the source code but only at debugging time (with F11 like you did in your video). But I can't access the source code by doing F12 (to reach implementation of a function for example) during the coding time (when the project is not running in debug), or when using the search engine of Visual Studio (like CTRL + , ). – El MoZo Aug 23 '17 at 12:06
  • @ElMoZo, Thanks for your reply. If you want to access the source code by F12 in the coding time, you can try to create another project in your solution, put the DLL source in there, and then from your main project, add the dependency as a project reference instead of an assembly reference. Or you can use the tool ReSharper. For the detail info, please check the Update check the source code in dll by F12 in the answer. – Leo Liu Aug 24 '17 at 03:10
  • 2
    The solution you provide to access the source code by F12 seems to be technically what we were doing before we put our framework in a nuget... If we do this we'll have to ref, one for the nuget and one for the side project with the source ? – El MoZo Aug 24 '17 at 15:30
  • @ElMoZo, yes, you are right or you can use the tool ReSharper, but it is not free. – Leo Liu Aug 24 '17 at 16:03
  • Now beeing in 2020, is there a better way to teach VisualStudio to also check the SourceCode Files of the NugetPackages if using VS Search Enging or "Go to definition"? – phifi Jun 30 '20 at 13:06