在本机搭建私有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包 推上去就可以了。

相关推荐
RoboWizard3 分钟前
金士顿高速闪存盘 单双接口适配多元存储需求
大数据·运维·人工智能·智能手机·云计算
2601_964702899 分钟前
Claude Opus 5 API 开发实战:对话、文本生成与结构化输出
java·服务器·前端
聚焦前沿10 分钟前
水动力优化导流罩:原理、数据与实船验证
大数据·服务器·数据库·人工智能
hkj880811 分钟前
Ubuntu 20.04 安装 OpenJDK 17
linux·运维·ubuntu
huainingning13 分钟前
防火墙重启后ssl登录提示证书过期临时解决方法
linux·服务器·ssl
sulikey19 分钟前
服务器安装Docker教程。如何在云服务器安装Docker容器?
运维·服务器·ubuntu·docker·安装教程·云服务器
许彰午22 分钟前
17-22-运维与高级主题
运维·网络
万联WANFLOW22 分钟前
外贸独立站:服务器放海外国内后台卡,放国内海外客户打不开——这道两头难怎么破?
运维·网络·数据库·经验分享
跨境小彭24 分钟前
Temu 店群自动化核价落地实践:告别人工熬夜议价,依托智能核价极速版规避操作亏损
运维·自动化·跨境电商·temu
池央39 分钟前
NAS里的大文件怎么快速传?用Copyparty搭建轻量文件服务器
运维·服务器·cpolar