简体   繁体   English

在Visual Studio中向项目添加引用和添加Nuget包之间的区别

[英]Difference between adding a Reference and adding a Nuget package to a project in Visual Studio

I have a VS (2015) project. 我有一个VS(2015)项目。 I see there's a "References" section in the Solution Explorer view of my project that includes things like System.Core. 我看到项目的“解决方案资源管理器”视图中有一个“参考”部分,其中包括诸如System.Core之类的内容。 I'm assuming these are .dlls that have been added to the project? 我假设这些是已添加到项目中的.dll?

I can also right-click on the project file (again in the Solution Explorer) and select the option to "Manage NuGet Packages". 我也可以右键单击项目文件(同样在解决方案资源管理器中),然后选择“管理NuGet程序包”选项。 I know the NuGet allows me to add external code to my project (eg external .dlls and associated files). 我知道NuGet允许我向项目添加外部代码(例如,外部.dll和关联文件)。

What's the difference between adding a reference to my project and adding a .nupkg to my project? 向项目添加引用与向项目添加.nupkg有什么区别? Is it just that .nupkg can contain a whole bunch of other things aside from a .dll (eg documentation)? 仅仅是.nupkg可以包含.dll以外的其他内容(例如文档)吗? Why would I use one or the other? 为什么要使用其中一个?

What's the difference between adding a reference to my project and adding a .nupkg to my project? 向项目添加引用与向项目添加.nupkg有什么区别?

NuGet essentially does not differ from manually adding references, and ultimately adds references to the project. NuGet本质上与手动添加引用没有什么不同,并且最终将引用添加到项目中。 It is a tool that automatically adds assemblies to us and manages them, effectively improving the efficiency of our development projects. 它是一种自动向我们添加程序集并对其进行管理的工具,有效地提高了我们开发项目的效率。

For more details, you can check the document about nuget : 有关更多详细信息,可以查看有关nuget的文档

Put simply, a NuGet package is a single ZIP file with the .nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number. 简而言之,NuGet软件包是一个扩展名为.nupkg的单个ZIP文件,其中包含编译代码(DLL),与该代码相关的其他文件以及一个描述性清单,其中包含诸如软件包的版本号之类的信息。 Developers with code to share create packages and publish them to a public or private host. 具有共享代码的开发人员可以创建软件包并将其发布到公共或私有主机。 Package consumers obtain those packages from suitable hosts, add them to their projects, and then call a package's functionality in their project code. 包使用者从合适的主机获取那些包,将它们添加到他们的项目中,然后在他们的项目代码中调用包的功能。 NuGet itself then handles all of the intermediate details. 然后,NuGet本身会处理所有中间细节。

Because NuGet supports private hosts alongside the public nuget.org host, you can use NuGet packages to share code that's exclusive to an organization or a work group. 因为NuGet支持私有主机和公共nuget.org主机,所以您可以使用NuGet包共享组织或工作组专有的代码。 You can also use NuGet packages as a convenient way to factor your own code for use in nothing but your own projects. 您还可以使用NuGet包作为方便的方法来分解您自己的代码,以便仅在您自己的项目中使用。 In short, a NuGet package is a shareable unit of code, but does not require nor imply any particular means of sharing. 简而言之,NuGet包是可共享的代码单元,但既不需要也不暗示任何特定的共享方式。

.

Is it just that .nupkg can contain a whole bunch of other things aside from a .dll (eg documentation)? 仅仅是.nupkg可以包含.dll以外的其他内容(例如文档)吗?

Yes, NuGet package could include specify files in the package. 是的,NuGet软件包可以在软件包中包含指定文件。

Why would I use one or the other? 为什么要使用其中一个?

Nuget provides several additional benefits: Nuget提供了其他一些好处:

  • it automatically configures your projects by adding references to the necessary assemblies, creating and adding project files (eg configuration), etc. 它通过添加对必要程序集的引用,创建和添加项目文件(例如配置)等自动配置您的项目。
  • it provides package updates 它提供软件包更新
  • it does all of this very conveniently 它非常方便地完成所有这些操作

I'm sure that once you use it, you'll realize that it has many benefits. 我相信一旦使用它,您就会意识到它有很多好处。

Check Why use NuGet for more details. 有关更多详细信息,请检查为什么使用NuGet

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio - 将 Nuget package 添加到 MacOs 中的项目时,拒绝访问路径“/Users/.local/share/NuGet” - Visual Studio - Access to the path '/Users/.local/share/NuGet' is denied when adding Nuget package to the project in MacOs 创建已包含 Nuget Package 参考的 Visual Studio 项目模板? - Creating a Visual Studio Project Template that already includes a Nuget Package Reference? 在Visual Studio Solution中添加GitHub项目作为参考 - Adding GitHub project as reference in Visual Studio Solution Visual Studio Community 2015添加了对项目的引用 - Visual Studio Community 2015 adding a reference to project 安装 NuGet 包而不在 Visual Studio 中添加任何引用 - Install NuGet package without adding any references in Visual Studio Nuget软件包未添加软件包参考 - Nuget-package not adding package reference 如何更改 Visual Studio 项目中的 NuGet 包引用以使用 Nuget.config - How to change the NuGet-package reference in a Visual Studio project to use Nuget.config 如何在Visual Studio中提供Nuget包的引用 - How to give reference of Nuget package in Visual Studio 参考、模板和 NuGet 包之间的区别? - Difference between Reference, Template, and a NuGet package? Visual Studio Code添加特定版本的程序包引用 - Visual Studio Code adding a package reference for a specific version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM