nuget私域部署(BaGet)及其使用

1.引言

在C#软件项目开发过程中,会频繁对第三方的组件进行引用。第三方的组件除了VS自带的nuget库(https://api.nuget.org/v3/index.json)之外,公司内部本身也会开发,特别是运营SAAS商业模式的公司,内部开发的组件互相引用尤为突出。
本文针对部分企业需求,整理了公司内部私域部署nuget及其使用的示例以供参考。

2.BaGet简介

BaGet是一个构建于ASP.NET Core 基础上的 NuGet V3 服务器的开源实现。
BaGet开源项目地址:https://github.com/loic-sharma/BaGet
release包:https://github.com/loic-sharma/BaGet/releases
本项文档release包:https://github.com/loic-sharma/BaGet/releases/download/v0.4.0-preview2/BaGet.zip
官方文档:https://learn.microsoft.com/zh-cn/nuget/create-packages/creating-a-package

3.部署

3.1环境安装

nuget的环境安装包(如果需要的话):https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/sdk-3.1.426-windows-x64-installer

3.2Baget安装

下载release包:https://github.com/loic-sharma/BaGet/releases/download/v0.4.0-preview2/BaGet.zip
在这里插入图片描述
下载完成的文件目录如下(需解压):
在这里插入图片描述
用cmd,在此目录下执行dotnet BaGet.dll
在这里插入图片描述
运行成功之后,访问http://localhost:5000/
结果如下,则表示安装完成
在这里插入图片描述

4.实现自动上传nuget

进入“工具-外部工具”菜单,添加一个新的命令,如下
在这里插入图片描述
标题:发布本地Nuget
命令:cmd.exe
参数:/c del /s /q *.nupkg && dotnet pack $(ProjectFileName) -c Debug -o KaTeX parse error: Expected 'EOF', got '&' at position 14: (ProjectDir) &̲& dotnet nuget …(ProjectDir)

4.1创建一个core项目,用于打包

新建一个core类库项目,目前的版本只有core的项目才具备自动打包功能。
在这里插入图片描述
执行“工具-发布本地Nuget”
在我们发布的nuget上即可看到我们新发布的dll
在这里插入图片描述
修改发布的网址,可通过修改appsettings.json的Kestrel来实现,如下

"Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://1localhost:5001"
      }
    }
  },

完整配置如下

{
  "ApiKey": "",
  "PackageDeletionBehavior": "Unlist",
  "AllowPackageOverwrites": false,

  "Database": {
    "Type": "Sqlite",
    "ConnectionString": "Data Source=baget.db"
  },

  "Storage": {
    "Type": "FileSystem",
    "Path": ""
  },

  "Search": {
    "Type": "Database"
  },

  "Mirror": {
    "Enabled": false,
    // Uncomment this to use the NuGet v2 protocol
    //"Legacy": true,
    "PackageSource": "https://api.nuget.org/v3/index.json"
  },

  // Uncomment this to configure BaGet to listen to port 8080.
  // See: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#listenoptionsusehttps
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5001"
      }
    }
  },

  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "Console": {
      "LogLevel": {
        "Microsoft.Hosting.Lifetime": "Information",
        "Default": "Warning"
      }
    }
  }
}

4.2使用发布的组件

配置nuget包服务器
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

5.非core项目(Framework)转package

创建framwork的类库项目
在这里插入图片描述
下载nuget.exe(https://www.nuget.org/downloads)
在这里插入图片描述
复制文件到debug下
在这里插入图片描述
执行cmd
在这里插入图片描述
执行nuget spec命令
在这里插入图片描述
可以看到文件
在这里插入图片描述
nuget pack
在这里插入图片描述

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

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
如反炮制,也可以设置命令来实现便捷上传

在这里插入图片描述

6.删除包

dotnet nuget delete -s http://localhost:5000/v3/index.json NugetTool 1.0.0

提示

将从http://localhost:5000/api/v2/package'删除 1.0.0。是否继续?(y/N)

输入y,表示确认删除

warn:正在从'http://localhost:5000/api/v2/package'删除  1.0.0.warn : You are running the 'delete' operation withan'HTTP'source,http://172.28.88.84:5000/api/v2/packaPS access will be removed in a future version. Consider :migrating to an 'HTTP' Ssource.
DELETE http://localhost:5000/api/v2/package/ /1.0.0
NoContent http://localhost:5000/api/v2/package/ /1.0.0 159毫秒
已成功删除 1.0.0。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值