一 下载网址

Nuget下载网站

二 需要关注的点

1.依赖框架

如果没有说明Dependencies则是仅支持NET Framework.

image.png

2.版本

image.png

3.安装(图形化和非图形化)

命令行形式:Nuget命令行(在工具栏菜单)image.png
图形化:右键项目—Nuget包管理—搜索需要的包
关于卸载,可直接双击项目进行ItemGroup中的包信息链接删除即可卸载。

三、内部搭建Nuget服务器(一)

参考文章:Nuget私有服务器搭建 Nuget打包和发布
1.开启IIS服务器 Windows平台下 控制面板—程序和功能 开启这些项目
image.png
image.png

  1. 创建ASP.NET Web应用程序空项目

image.png
3.为新项目引用Nuget包:Nuget.Server
image.png
4.发布项目到本地文件夹 注意不要把项目发布包放在C盘下
image.png
5.打开IIS管理器,添加发布包部署到服务器上
image.png
6.使用Nuget Package Explorer(微软商店)进行打包上传
7.调用:点击工具 > 选择NuGet包管理 > 包管理设置>package来源>点击加号>来源填上私有的NuGet服务器地址(http://172.18.8.150:8196/nuget)

四 Baget搭建私有服

  1. 下载Baget Release包并上传到服务器中 https://github.com/loic-sharma/BaGet/releases
  2. Baget.dll 是基于.NET Core3.1 下载3.1的SDK
  3. 到Baget目录下执行 dotnet baget.dll 启动后台服务
  4. 写好类库项目,例如基于.NET6的TestNuget 功能写完直接打包
  5. 微软商店下载 Nuget Package Explorer,用Nuget Package Explorer打开上一步生成好的包,修改信息 必要字段ID Author Description
  6. 发布:File-Publish PublishUrl:http://139.196.89.233:8044/v3/index.json PublishKey:服务器中appsetting.json的Key

image.png

  1. 删除Baget包: dotnet nuget delete PackageName PackageVersion -s Url(http://139.196.89.233:8044/v3/index.json) -k apikeyself

    五 通过IIS来部署Baget:

    web.config:必须要添加modules两个remove模块

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <configuration>
    3. <location path="." inheritInChildApplications="false">
    4. <system.webServer>
    5. <handlers>
    6. <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    7. </handlers>
    8. <modules>
    9. <remove name="WebDAVModule"/>
    10. <remove name="WebDAV" />
    11. </modules>
    12. <aspNetCore processPath="dotnet" arguments=".\BaGet.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    13. </system.webServer>
    14. </location>
    15. </configuration>

    appsettings.json:启用硬删除

    ```csharp { “ApiKey”: “albertzhaonuget”, “Urls”:”http://*:8044“, “PackageDeletionBehavior”: “HardDelete”, “AllowPackageOverwrites”: true,

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

    “Storage”: { “Type”: “FileSystem”, “Path”: “” },

    “Search”: { “Type”: “Database” },

    “Mirror”: { “Enabled”: true, // 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:8080“ // } // } // },

    “Logging”: { “IncludeScopes”: false, “Debug”: { “LogLevel”: {

    1. "Default": "Warning"

    } }, “Console”: { “LogLevel”: {

    1. "Microsoft.Hosting.Lifetime": "Information",
    2. "Default": "Warning"

    } } } }

```

在IIS管理器中创建应用程序池

03 NuGet注意点及私有服务器搭建 - 图12

创建网站:IP地址那一栏可以不写,端口更改为8044

03 NuGet注意点及私有服务器搭建 - 图13
测试设置如果不通过,点击连接为,用Administrator 账户密码登录即可。

启用所有权限

image.png
image.png

推送 删除

推送 dotnet nuget push -s http://139.196.89.233:8044 -k 【apikey】 TestBagetTwo.1.0.0.nupkg
删除 dotnet nuget delete TestBaget 1.0.0 -s http://139.196.89.233:8044 -k 【apikey】

六 使用

在Visual Studio中增加Nuget源:v3/index.json是必须的。
image.png
Github ProduceTool小工具:

  • albert baget list 列出远端所有的Nuget
  • albert baget del -n PackageName -v PackageVersion 删除指定版本号的包
  • albert baget push “我是路径” 上传指定路径下所有Nuget包到服务器上,服务器包是否允许覆盖请查阅Baget参数设置。