在本机搭建私有NuGet服务器

写在前面

有时我们不想对外公开源码,同时又想在VisualStudio中通过Nuget包管理器来统一管理这些内部动态库,这时就可以在本地搭建一个NuGet服务器。

操作步骤

1.下载BaGet

这是一个轻量级的NuGet服务器

2.部署BaGet

将下载好的release版本BaGet解压至 C:\inetpub\wwwroot\BaGet

在IIS中新建应用程序池

新建网站,并指定BaGetAppPool 作为应用程序池,绑定域名 test.com

重点来了,修改BaGet站点下的 web.config 配置

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />      
      </handlers>
      <modules>
        <remove name="WebDAVModule"/>
        <remove name="WebDAV" />
      </modules>
      <aspNetCore processPath="dotnet" arguments=".\BaGet.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
    <system.webServer>
        <httpErrors errorMode="DetailedLocalOnly" />
    </system.webServer>
</configuration>

修改appsettings.json配置

javascript 复制代码
{
  "ApiKey": "ACMR",
  "Urls":"http://*:82",
  "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"
  }, 
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "Console": {
      "LogLevel": {
        "Microsoft.Hosting.Lifetime": "Information",
        "Default": "Warning"
      }
    }
  }
}

3.修改hosts 映射

C:\Windows\System32\drivers\etc\hosts

127.0.0.1 test.com

这样就可以在本地模拟通过域名来访问了。

运行示例

接下来把做好的nuget包 推上去就可以了。

相关推荐
Agent产品评测局3 分钟前
律所行业自动化平台选型,合同审核与案件管理优化 | 2026年法律科技Agent化演进与企业级智能体实测横评
运维·人工智能·科技·ai·chatgpt·自动化
思麟呀3 分钟前
应用层协议HTTP
linux·服务器·网络·c++·网络协议·http
何中应9 分钟前
Docker-Compose环境配置&使用
运维·docker·容器
南境十里·墨染春水1 小时前
linux学习进展 信号
linux·服务器·学习
YuanDaima20481 小时前
堆(优先队列)基础原理与题目说明
linux·运维·服务器·人工智能·python··代码
another heaven1 小时前
【软考 对称加密与非对称加密】
服务器·网络
生万千欢喜心1 小时前
linux 安装 人大金仓数据库
linux·运维·数据库
傻啦嘿哟1 小时前
Python多进程编程:用multiprocessing突破GIL限制
服务器·网络·数据库
Finn Wang1 小时前
KeyPresser 一款自动化按键工具
运维·自动化
@insist1231 小时前
网络工程师-网络规划与设计(三):数据中心机房设计规范全解析
服务器·网络·数据库·网络工程师·软考·软件水平考试