5

10分钟学会VS NuGet包私有化部署

 3 years ago
source link: https://www.cnblogs.com/xiongze520/p/15242877.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client



我们之前实现了打包发布NuGet,但是发布后的引用是公有的,谁都可以访问,显然这种方式是不可取的。

命令版本:10分钟学会Visual Studio将自己创建的类库打包到NuGet进行引用(net,net core,C#)

web版本(推荐):小白2分钟学会Visual Studio将引用包打包到NuGet上

其实官方也提供了私有化部署(NuGet.Server、ProGet、MyGe等),我们就来基于BaGet进行搭建一个私有NuGet环境。


什么是BaGet

BaGet 是GitHub上开源的一个项目,是一个轻量级NuGet和符号服务器,是NuGet V3 服务器的开源实现。

搭建私有化BaGet服务器

我们以自己的本地环境充当服务器环境为例

进入BaGet下载地址下载release包,下面是我下载的版本,你也可以选择其他版本:

https://github.com/loic-sharma/BaGet/releases/download/v0.3.0-preview4/BaGet.zip

如下讲解怎么选择版本下载,点击进入BaGet下载地址,点击Releases选择版本,进入后点击BaGet.zip进行下载。

BaGet下载地址:https://github.com/loic-sharma/BaGet

 将下载后的BaGet.zip文件解压,修改appsetting.json 配置文件,不需要修改什么,只需要修改自己的api keys和服务器地址即可。由于这里是测试,api keys就不填了,不影响操作。。

里面的具体配置操作可参考官方文档

注意启动服务的前提是要安装.NetCore SDK,由于安装了.NET Core,所以自带的有,如果没有的需要安装sdk。

BaGet.zip文件解压目录(BaGet文件目录)下打开命令行,执行:dotnet BaGet.dll

执行:dotnet BaGet.dll

打开浏览器,运行http://localhost:5000 即可看到nuget 服务已启动。


上传程序包到私有化服务器

创建一个类库用于测试,我们还是以之前的“繁简体相互换换”为例。

using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
using System;

namespace XiongZeUtils
{
    public static class xzUtils
    {
        /// <summary> 
        /// 简体转换为繁体
        /// </summary> 
        /// <param name="str">简体字</param> 
        /// <returns>繁体字</returns> 
        public static string GetTraditional(string str)
        {
            string r = string.Empty;
            r = ChineseConverter.Convert(str, ChineseConversionDirection.SimplifiedToTraditional);
            return r;
        }
        /// <summary> 
        /// 繁体转换为简体
        /// </summary> 
        /// <param name="str">繁体字</param> 
        /// <returns>简体字</returns> 
        public static string GetSimplified(string str)
        {
            string r = string.Empty;
            r = ChineseConverter.Convert(str, ChineseConversionDirection.TraditionalToSimplified);
            return r;
        }
    }
}

右键项目,选择打包:

打包完成会得到一个nupkg文件,版本在右键-》属性-》打包里面进行配置:

在刚刚的浏览器看一下看一下Upload命令:

在上面打包目录下打开命令行执行:

dotnet nuget push -s http://localhost:5000/v3/index.json XiongZeUtils.1.0.3.nupkg

注意,这里是打包路径,也就是生成XiongZeUtils.1.0.3.nupkg文件的目录,和上面解压目录执行dotnet BaGet.dll的是两个地方,不要混淆。

推送包成功后,我们再去http://localhost:5000/的Packages查看一下,私有化打包发布成功。


使用私有化程序包

在vs2019中打开:工具-选项-NuGet包管理器-程序包源。添加一个源,输入名称,源:http://localhost:5000/v3/index.json(自己的服务器地址)

 在NuGet里面就能查询到私有服务器上的程序包了


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK