搭建自己的nuget服务器_如何托管自己的NuGet服务器和软件包提要

  • Post author:
  • Post category:其他


搭建自己的nuget服务器

搭建自己的nuget服务器

Local NuGet Feed

Hosting your own NuGet Server, particularly when you’re a company or even a small workgroup is a super useful thing. It’s a great way to ensure that the build artifacts of each team are NuGet Packages and that other teams are consuming those packages, rather than loose DLLs.

托管自己的NuGet服务器,特别是在公司或什至是小型工作组的情况下,都是非常有用的。 这是确保每个团队的构建工件都是NuGet软件包的好方法,并且确保其他团队正在使用这些软件包,而不是松散的DLL。

A lot of folks (myself included a minute ago) don’t realize

that Visual Studio Team Services also offers private NuGet Feeds for your team

so that’s pretty sweet. But I wanted to try out was setting up my own quick NuGet Server. I could put it on a web server in my closet or up in Azure.

许多人(包括我自己在内的一分钟前)都没有意识到

Visual Studio Team Services还为您的团队提供了私有的NuGet Feed,

这真是太好了。 但我想尝试设置自己的快速NuGet服务器。 我可以将其放在壁橱中的Web服务器上或Azure中。

From

the NuGet site

:



NuGet网站

There are several third-party NuGet Servers available that make remote private feeds easy to configure and set-up, including

Visual Studio Team Services

,

MyGet

,

Inedo’s ProGet

,

JFrog’s Artifactory

,

NuGet Server

, and

Sonatype’s Nexus

. See

An Overview of the NuGet Ecosystem

to learn more about these options.

有几种第三方NuGet服务器可用,它们使远程私人供稿易于配置和设置,包括

Visual Studio Team Services



MyGet



Inedo的ProGet



JFrog的Artifactory



NuGet服务器



Sonatype的Nexus

。 请参阅

NuGet生态系统概述,

以了解有关这些选项的更多信息。

文件共享或目录作为NuGet服务器

(

File Shares or Directories as NuGet Server

)

Starting with NuGet 3.3 you can just use a local folder and it can host a hierarchical NuGet feed. So I head out to the command line, and first make sure NuGet is up to date.

从NuGet 3.3开始,您只能使用本地文件夹,并且可以承载分层的NuGet源。 因此,我进入命令行,首先确保NuGet是最新的。

C:\Users\scott\Desktop>nuget update -self
Checking for updates from https://www.nuget.org/api/v2/.
Currently running NuGet.exe 3.3.0.
NuGet.exe is up to date.

Then I’ll make a folder for my “local server” and then go there and run “nuget init source dest” where “source” is a folder I have full of *.nupkg” files.

然后,我将为“本地服务器”创建一个文件夹,然后去那里并运行“ nuget init source dest”,其中“ source”是一个文件夹,其中包含* .nupkg”个文件。



This command adds all the packages from a flat folder of nupkgs to the destination package source in a hierarchical layout as described below. The following layout has significant performance benefits, when performing a restore or an update against your package source, compared to a folder of nupkg files.



该命令将所有软件包从nupkgs的平面文件夹添加到目标软件包源中,并采用如下所述的分层布局。 与nupkg文件文件夹相比,当对包源执行还原或更新时,以下布局具有显着的性能优势。

There’s two ways to run a “remote feed” handled by a Web Server, rather than a “local feed” that’s just a file folder or file share. You can use NuGet.Server *or*

run your own internal copy of the NuGet Gallery

. The gallery is nice for large multi-user setups or enterprises. For small teams or just yourself and your CI (continuous integration) systems, use NuGet.Server.

有两种方法来运行由Web服务器处理的“远程供稿”,而不是仅是文件夹或文件共享的“本地供稿”。 您可以使用NuGet.Server *或*

运行自己的NuGet Gallery内部副本

。 该库非常适合大型多用户设置或企业。 对于小型团队,或者只是您自己和您的CI(连续集成)系统,请使用NuGet.Server。

制作一个简单的基于Web的NuGet.Server

(

Making a simple Web-based NuGet.Server

)

From Visual Studio, make an empty ASP.NET Web Application using the ASP.NET 4.x

Empty

template.

在Visual Studio中,使用ASP.NET 4.x



模板创建一个空的ASP.NET Web应用程序。

New Empty ASP.NET Project

Then, go to References | Manage NuGet Packages and find NuGet.Server and install it. You’ll get all the the dependencies you need and your Empty Project will fill up! If you see a warning about overwriting web.config, you DO want the remote web.config so overwrite your local one.

然后,转到参考| 管理NuGet软件包并找到NuGet.Server并安装它。 您将获得所需的所有依赖项,您的空白项目将满! 如果看到有关覆盖web.config的警告,则表示您确实希望远程web.config覆盖本地的。

Nuget install NuGet.Server

Next, go into your Web.config and note the packagesPath that you can set. I used C:\LocalNuGet. Run the app and you’ll have a NuGet Server!

接下来,进入您的Web.config并记下您可以设置的packagesPath。 我使用了C:\ LocalNuGet。 运行该应用程序,您将拥有一个NuGet服务器!

You are running NuGet.Server v2.10.0

Since my NuGet.Server is pulling from C:\LocalNuGet, as mentioned before I can take a folder filled with NuPkg files (flat) and import them with:

由于我的NuGet.Server是从C:\ LocalNuGet提取的,因此如前所述,我可以将一个装有NuPkg文件(平面)的文件夹导入并使用以下命令导入:

nuget init c:\source c:\localnuget

I can also set an API key in the web.config (or have none if I want to live dangerously) and then have my automated build push NuGet packages into my server like this:

我还可以在web.config中设置一个API密钥(如果我想过着危险的生活,则没有密钥),然后让我的自动构建将NuGet软件包推送到服务器中,如下所示:

nuget push {package file} -s http://localhost:51217/nuget {apikey}

Again, as a reminder, while you can totally do this and it’s great for some enterprises, there are lots of hosted NuGet servers out there.

MyGet runs on Azure

, for example, and

VSO/TFS also supports creating and hosting NuGet feeds

.

再次提醒您,虽然您可以完全做到这一点,并且对某些企业来说非常好,但是这里有很多托管的NuGet服务器。 例如,

MyGet在Azure上运行

,并且

VSO / TFS还支持创建和托管NuGet feed


Aside:

Some folks have said that they tried NuGet.Server (again, that’s the small server, not the full gallery) a few years ago and found it didn’t scale or it was slow. This new version

uses the Expanded Folder Format

and adds significant caching, so if you’ve only see the “folder full of flat nupkg files” version, then you should try out this new one! It’s version 2.10+. How much faster is it? First request to

/nuget

(cold start, no metadata cache) before was 75.266 sec and after is 8.482 sec!

旁白



有些人说几年前他们尝试了NuGet.Server(同样,这是小型服务器,而不是完整的库),发现它没有扩展或速度很慢。 这个新版本

使用扩展文件夹格式

并添加了显着的缓存,因此,如果您仅看到“完整的平面nupkg文件文件夹”版本,那么您应该尝试这个新版本! 它是版本2.10+。 它快多少? 到

/nuget

第一个请求(冷启动,没有元数据缓存)之前为75.266秒,之后为8.482秒!

The main point is that if you’ve got an automated build system then you really should be creating NuGet packages and publishing them to a feed. If you’re consuming another group’s assemblies, you should be consuming versioned packages from their feeds. Each org makes packages and they flow through the org via a NuGet server.

要点是,如果您拥有自动化的构建系统,那么您确实应该创建NuGet软件包并将其发布到feed中。 如果使用另一个组的程序集,则应使用其提要中的版本化程序包。 每个组织制作软件包,然后它们通过NuGet服务器流经组织。


Important!

If you are

using a Network Share with NuGet.Server

, make sure you have the newest version because this file folder structure can give you MAJOR performance improvements!


重要!

如果您将

网络共享与NuGet.Server一起使用

,请确保您具有最新版本,因为此文件夹结构可以

极大地

提高性能!

How do YOU handle NuGet in YOUR organization? Do you have a NuGet server, and if so, which one?

在组织中如何处理NuGet? 您是否有NuGet服务器,如果有,那是哪一个?


Sponsor:

Big thanks to RedGate and my friends on ANTS for sponsoring the feed this week!


赞助商:

非常感谢RedGate和我在ANTS上的朋友为本周的feed赞助!

How can you find & fix your slowest .NET code? Boost the performance of your .NET application with the

ANTS Performance Profiler

. Find your bottleneck fast with performance data for code & queries.

Try it free

如何找到并修复最慢的.NET代码? 使用

ANTS Performance Profiler

提高.NET应用程序的

性能

。 利用代码和查询的性能数据快速找到瓶颈。

免费尝试

翻译自:

https://www.hanselman.com/blog/how-to-host-your-own-nuget-server-and-package-feed

搭建自己的nuget服务器