架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11867|回复: 1

[资料] Nuget系列(一)使用 asp.net 搭建私有 Nuget 仓库

[复制链接]
发表于 2020-8-30 18:50:02 | 显示全部楼层 |阅读模式
在项目开发中,我们经常会使用到第三方的类库,可以通过下载引用的方式调用,也可以通过 nuget 官网下载公开的插件。

nuget地址:https://www.nuget.org/

Nuget是一个.NET平台下的开源的项目,它是Visual Studio的扩展。在使用Visual Studio开发基于.NET Framework的应用时,Nuget能把在项目中添加、移除和更新引用的工作变得更加快捷方便。这是维基百科中的定义,实际上Nuget就是一个包管理器,类似于Java的Maven,可以帮助我们更方便的管理dll。

nuget官网都是公开的类库,如果你将自己的类库上传上去,也将会提供给其他人下载安装调用。由于公司、团队开发的项目,会涉及到商业机密或者隐私,不想公开发行,需要我们自己搭建一个私有的 nuget 仓库。
Nuget 私有仓库

首先,新建一个 asp.net web 应用程序,选择空模板 NugetDepot(.NET 4.7.2)项目。

QQ截图20200830150203.jpg

项目安装 Nuget.Server 包,命令如下:

每个包都由其所有者许可给你。NuGet 不负责第三方包,也不授予其许可证。一些包可能包括受其他许可证约束的依赖关系。单击包源(源) URL 可确定任何依赖关系。

程序包管理器控制台主机版本 5.4.0.6292

键入 "get-help NuGet" 可查看所有可用的 NuGet 命令。

PM> Install-Package NuGet.Server -Version 3.4.1


正在尝试收集与目标为“.NETFramework,Version=v4.7.2”的项目“NugetDepot”有关的包“NuGet.Server.3.4.1”的依赖项信息
收集依赖项信息花费时间 5.33 sec
正在尝试解析程序包“NuGet.Server.3.4.1”的依赖项,DependencyBehavior 为“Lowest”
解析依赖项信息花费时间 0 ms
正在解析操作以安装程序包“NuGet.Server.3.4.1”
已解析操作以安装程序包“NuGet.Server.3.4.1”
  GET https://api.nuget.org/v3-flatcon ... ata.edm.5.8.4.nupkg
  GET https://api.nuget.org/v3-flatcon ... t.core.2.14.0.nupkg
  GET https://api.nuget.org/v3-flatcon ... er.core.3.4.1.nupkg
  GET https://api.nuget.org/v3-flatcon ... web.xdt.2.1.1.nupkg
  OK https://api.nuget.org/v3-flatcon ... ata.edm.5.8.4.nupkg 197 毫秒
正在安装 Microsoft.Data.Edm 5.8.4。
  OK https://api.nuget.org/v3-flatcon ... t.core.2.14.0.nupkg 790 毫秒
正在安装 NuGet.Core 2.14.0。
  OK https://api.nuget.org/v3-flatcon ... web.xdt.2.1.1.nupkg 1100 毫秒
正在安装 Microsoft.Web.Xdt 2.1.1。
  OK https://api.nuget.org/v3-flatcon ... er.core.3.4.1.nupkg 3627 毫秒
正在安装 NuGet.Server.Core 3.4.1。
  GET https://api.nuget.org/v3-flatcon ... spatial.5.8.4.nupkg
  GET https://api.nuget.org/v3-flatcon ... a.odata.5.8.4.nupkg
  OK https://api.nuget.org/v3-flatcon ... spatial.5.8.4.nupkg 171 毫秒
正在安装 System.Spatial 5.8.4。
  OK https://api.nuget.org/v3-flatcon ... a.odata.5.8.4.nupkg 179 毫秒
正在安装 Microsoft.Data.OData 5.8.4。
  GET https://api.nuget.org/v3-flatcon ... i.odata.5.7.0.nupkg
  OK https://api.nuget.org/v3-flatcon ... i.odata.5.7.0.nupkg 617 毫秒
正在安装 Microsoft.AspNet.WebApi.OData 5.7.0。
  GET https://api.nuget.org/v3-flatcon ... rver.v2.3.4.1.nupkg
  GET https://api.nuget.org/v3-flatcon ... vatorex.2.2.0.nupkg
从“nuget.org”检索包“Microsoft.AspNet.WebApi 5.2.3”
从“nuget.org”检索包“Microsoft.AspNet.WebApi.Client 5.2.3”
从“nuget.org”检索包“Microsoft.AspNet.WebApi.Core 5.2.3”
从“nuget.org”检索包“Microsoft.AspNet.WebApi.OData 5.7.0”
从“nuget.org”检索包“Microsoft.AspNet.WebApi.WebHost 5.2.3”
从“nuget.org”检索包“Microsoft.Data.Edm 5.8.4”
从“nuget.org”检索包“Microsoft.Data.OData 5.8.4”
从“nuget.org”检索包“Microsoft.Web.Infrastructure 1.0.0”
从“nuget.org”检索包“Microsoft.Web.Xdt 2.1.1”
从“nuget.org”检索包“Newtonsoft.Json 9.0.1”
从“nuget.org”检索包“NuGet.Core 2.14.0”
从“nuget.org”检索包“NuGet.Server 3.4.1”
从“nuget.org”检索包“NuGet.Server.Core 3.4.1”
从“nuget.org”检索包“NuGet.Server.V2 3.4.1”
从“nuget.org”检索包“System.Spatial 5.8.4”
从“nuget.org”检索包“WebActivatorEx 2.2.0”
  GET https://api.nuget.org/v3-flatcon ... .server.3.4.1.nupkg
正在将程序包“Microsoft.Data.Edm.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Data.Edm.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
  OK https://api.nuget.org/v3-flatcon ... vatorex.2.2.0.nupkg 484 毫秒
正在安装 WebActivatorEx 2.2.0。
已将程序包“Microsoft.Data.Edm.5.8.4”添加到“packages.config”
已将“Microsoft.Data.Edm 5.8.4”成功安装到 NugetDepot
正在将程序包“Microsoft.Web.Infrastructure.1.0.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Web.Infrastructure.1.0.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Web.Infrastructure.1.0.0”添加到“packages.config”
已将“Microsoft.Web.Infrastructure 1.0.0”成功安装到 NugetDepot
正在将程序包“Microsoft.Web.Xdt.2.1.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Web.Xdt.2.1.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Web.Xdt.2.1.1”添加到“packages.config”
已将“Microsoft.Web.Xdt 2.1.1”成功安装到 NugetDepot
正在将程序包“Newtonsoft.Json.9.0.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
  OK https://api.nuget.org/v3-flatcon ... .server.3.4.1.nupkg 1030 毫秒
正在安装 NuGet.Server 3.4.1。
已将程序包“Newtonsoft.Json.9.0.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
  OK https://api.nuget.org/v3-flatcon ... rver.v2.3.4.1.nupkg 1216 毫秒
正在安装 NuGet.Server.V2 3.4.1。
已将程序包“Newtonsoft.Json.9.0.1”添加到“packages.config”
正在执行脚本文件“C:\Users\itsvse_pc\source\repos\NugetDepot\packages\Newtonsoft.Json.9.0.1\tools\install.ps1”
已将“Newtonsoft.Json 9.0.1”成功安装到 NugetDepot
正在将程序包“Microsoft.AspNet.WebApi.Client.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.Client.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.Client.5.2.3”添加到“packages.config”
已将“Microsoft.AspNet.WebApi.Client 5.2.3”成功安装到 NugetDepot
正在将程序包“Microsoft.AspNet.WebApi.Core.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.Core.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.Core.5.2.3”添加到“packages.config”
已将“Microsoft.AspNet.WebApi.Core 5.2.3”成功安装到 NugetDepot
正在将程序包“Microsoft.AspNet.WebApi.WebHost.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.WebHost.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.WebHost.5.2.3”添加到“packages.config”
已将“Microsoft.AspNet.WebApi.WebHost 5.2.3”成功安装到 NugetDepot
正在将只有依赖项的程序包“Microsoft.AspNet.WebApi.5.2.3”添加到项目“NugetDepot”。
正在将程序包“Microsoft.AspNet.WebApi.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.5.2.3”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.5.2.3”添加到“packages.config”
已将“Microsoft.AspNet.WebApi 5.2.3”成功安装到 NugetDepot
正在将程序包“NuGet.Core.2.14.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Core.2.14.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Core.2.14.0”添加到“packages.config”
已将“NuGet.Core 2.14.0”成功安装到 NugetDepot
正在将程序包“NuGet.Server.Core.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.Core.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.Core.3.4.1”添加到“packages.config”
已将“NuGet.Server.Core 3.4.1”成功安装到 NugetDepot
正在将程序包“System.Spatial.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“System.Spatial.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“System.Spatial.5.8.4”添加到“packages.config”
已将“System.Spatial 5.8.4”成功安装到 NugetDepot
正在将程序包“Microsoft.Data.OData.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Data.OData.5.8.4”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.Data.OData.5.8.4”添加到“packages.config”
已将“Microsoft.Data.OData 5.8.4”成功安装到 NugetDepot
正在将程序包“Microsoft.AspNet.WebApi.OData.5.7.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.OData.5.7.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“Microsoft.AspNet.WebApi.OData.5.7.0”添加到“packages.config”
已将“Microsoft.AspNet.WebApi.OData 5.7.0”成功安装到 NugetDepot
正在将程序包“NuGet.Server.V2.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.V2.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.V2.3.4.1”添加到“packages.config”
已将“NuGet.Server.V2 3.4.1”成功安装到 NugetDepot
正在将程序包“WebActivatorEx.2.2.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“WebActivatorEx.2.2.0”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“WebActivatorEx.2.2.0”添加到“packages.config”
已将“WebActivatorEx 2.2.0”成功安装到 NugetDepot
正在将程序包“NuGet.Server.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.3.4.1”添加到文件夹“C:\Users\itsvse_pc\source\repos\NugetDepot\packages”
已将程序包“NuGet.Server.3.4.1”添加到“packages.config”
已将“NuGet.Server 3.4.1”成功安装到 NugetDepot
执行 nuget 操作花费时间 19.54 sec
已用时间: 00:00:25.0831394
PM>

他会自动修改 web.config 文件,以及新增 NuGetODataConfig.cs 等文件。

我们需要修改以下 web.config 文件,更新成自己需要的选项,配置如下:

同时,我们还需要修改 NuGetODataConfig.cs 文件,在程序启动的时候,创建 nuget 存放的路径,不建议放在网站根目录的某个文件夹下面。

我们将 nuget 包放在 E:\nuget_packages 目录下面,代码为:

尝试启动网站,如下图:

QQ截图20200830182955.jpg

推送到私有仓库

我们新建一个 netstandard2.0 的类库项目,同时,随便写些代码进行测试(如下),右击项目点击“打包”按钮,它将在在 C:\Users\itsvse_pc\source\repos\NugetDepot\ClassLibrary2\bin\Debug 目录下面,生成 ClassLibrary2.1.0.0.nupkg 文件

需要从 https://www.nuget.org/downloads 官网,下载 Nuget Windows x86 Commandline 工具 “nuget.exe”。

尝试如下命令,将 nuget 包推送到我们新建的私有仓库。

QQ截图20200830183710.jpg

其他命令,请参见文档:https://docs.microsoft.com/zh-cn/nuget/reference/cli-reference/cli-ref-push

安装私有包

在 vs 开发工具,添加 nuget 程序包源,如下图:

QQ截图20200830183938.jpg

新建一个 .Net Core 3.1 的控制台项目,安装我们上传的 nuget 包,命令如下:

QQ截图20200830184416.jpg

最后,附上源码下载:

游客,如果您要查看本帖隐藏内容请回复






上一篇:.NET/C# 远程桌面管理工具【附源码】
下一篇:JVM参数 Options
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
 楼主| 发表于 2020-9-9 22:55:17 | 显示全部楼层
Nuget系列(二)使用 BaGet 搭建私有 Nuget 服务
https://www.itsvse.com/thread-9380-1-1.html
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-4-20 04:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表