显示我的 nuget 的源代码

Show source code of my nuget(显示我的 nuget 的源代码)
本文介绍了显示我的 nuget 的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队构建了我们在许多项目中使用的自己的框架.我们曾经将框架的项目包含在我们所有其他项目中,但后来我们决定将我们的框架放入我们的 nuget 服务器上的 nuget 包宿主中,以便我们可以在开发过程中更轻松地进行版本控制和传播我们的框架.

一切都很好,但有一些明显的副作用.

Visual Studio 无法直接查看 nuget 的 dll 本身,因此例如 VS 搜索引擎无法查找我的 nuget 中存在的函数.出于同样的原因,我假设在我的项目中再也看不到我们框架的源代码,只显示了元数据.

我了解 nuget 包不显示其自己的源代码是正常行为,但我想知道是否可以将 nuget 包设置为受信任模式",以便 Visual Studio 能够搜索它里面的函数和开发人员可以直接查看源代码(当然不能编辑它).

非常感谢.

解决方案

这样 Visual Studio 将能够搜索其中的功能,并且开发人员能够直接查看源代码(当然不能对其进行编辑).

如果我知道你是正确的,你想访问 nuget 包中的代码但无法编辑?如果是,您可以尝试创建符号包,允许消费者在 Visual Studio 调试器中单步执行您的包代码.

我们的做法(和工作方式):

  1. 创建*.symbols.nupkg".

  2. 将符号包部署到 SymbolSource 服务器.

  3. 配置IDE,包消费者可以添加

    按F12更新查看dll中的源代码:

    根据MSDN 文档:

    <块引用>

    调试器在以下位置查找源文件:

    >1.在启动调试器的 Visual Studio 实例的 IDE 中打开的文件.>2.在 VS 实例中打开的解决方案中的文件.>3.在解决方案属性的通用属性"/调试源文件"页面中指定的目录.>4.模块的.pdb 的来源信息.这可以是构建模块时源文件的位置,也可以是对源服务器的命令.

所以如果你想直接F12访问dll文件中的源代码,你应该在解决方案中添加源代码.您可以在解决方案中创建一个新项目来存放源文件并将该项目添加为参考项目.这会使您的解决方案/项目变得混乱,但由于它将被检入源代码管理,所有团队成员都将能够自动调试源文件.

此外,应该推荐 ReSharper,您可以通过转到 ReSharper/Options/来启用它外部源,并向上移动来自符号文件的源".然后在来自符号文件的源"选项卡中,单击高级",您可以在其中映射源文件夹.

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.

解决方案

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:

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.

这篇关于显示我的 nuget 的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)