搭建公司内部的NuGet服务器

时间:2021-01-17 00:57:17
1.  创建NuGet项目
     (注意:解决方案名称可以自定义为其他的名称)
      搭建公司内部的NuGet服务器
2.   安装NuGet Server
      在 “NuGetServer” 项目上,右键选择 “管理NuGet程序包” ,选择 “联机” ,右上角搜索框中输入“NuGet.Server”  Enter,在搜索结果中选择 NuGet.Server 项,进行安装即可(如下图所示)。
      注意:如果安装最后,提示 替换 Web.config ,请选择“全是”。
      搭建公司内部的NuGet服务器
3.  编译NuGet Server项目
     编译“NuGetServer”项目,如果没有出异常,这里就创建项目完成,NuGetServer 就这么简单建成
     注意: 如果一直编译不过的话,则尝试多更新几次Nuget.Server包(卸载重新安装)。
     
4. 配置文件说明(Web.config)
    web.config->appSettings的各项配置说明:
    packagesPath:这个Key表示Nuget包的存放目录,默认情况下存放在部署的网站根目录Packages文件夹
    requireApiKey: 这个key 如果设置成 true ,表示apiKey是必须要设置的,这个就像密码一样。可以阻止不知道这个apiKey人访问到程序包
    apiKey: 搭建公司内部的NuGet服务器搭建公司内部的NuGet服务器是作为一个密钥,防止其他人来访问我们的Nuget服务(NuGet Package Explorer来访问的时候也许要填入我们预先设置好的密钥才能够进行访问)
 <?xml version="1.0" encoding="utf-8"?>
<!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 -->
<configuration>
<appSettings>
<!-- Determines if an Api Key is required to push\delete packages from the server. -->
<add key="requireApiKey" value="true" /> <!--
Set the value here to allow people to push/delete packages from the server.
NOTE: This is a shared key (password) for all users.
-->
<add key="apiKey" value="ChinaNet910111" />
<!--
Change the path to the packages folder. Default is ~/Packages.
This can be a virtual or physical path.
-->
<add key="packagesPath" value="~/Packages" /> <!--
Set allowOverrideExistingPackageOnPush to false to mimic NuGet.org's behaviour (do not allow overwriting packages with same id + version).
-->
<add key="allowOverrideExistingPackageOnPush" value="false" /> <!--
Set ignoreSymbolsPackages to true to filter out symbols packages. Since NuGet.Server does not come with a symbol server,
it makes sense to ignore this type of packages. When enabled, files named `.symbols.nupkg` or packages containing a `/src` folder will be ignored. If you only push .symbols.nupkg packages, set this to false so that packages can be uploaded.
-->
<add key="ignoreSymbolsPackages" value="true" /> <!--
Set enableDelisting to true to enable delist instead of delete as a result of a "nuget delete" command.
- delete: package is deleted from the repository's local filesystem.
- delist:
- "nuget delete": the "hidden" file attribute of the corresponding nupkg on the repository local filesystem is turned on instead of deleting the file.
- "nuget list" skips delisted packages, i.e. those that have the hidden attribute set on their nupkg.
- "nuget install packageid -version version" command will succeed for both listed and delisted packages.
e.g. delisted packages can still be downloaded by clients that explicitly specify their version.
-->
<add key="enableDelisting" value="false" /> <!--
Set enableFrameworkFiltering to true to enable filtering packages by their supported frameworks during search.
-->
<add key="enableFrameworkFiltering" value="false" /> <!--
When running NuGet.Server in a NAT network, ASP.NET may embed the erver's internal IP address in the V2 feed.
Uncomment the following configuration entry to enable NAT support.
-->
<!-- <add key="aspnet:UseHostHeaderForRequestUrl" value="true" /> -->
</appSettings>
<system.web>
<httpRuntime maxRequestLength="" />
<compilation debug="true" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".nupkg" mimeType="application/zip" />
</staticContent>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>

web.config

5. 部署IIS站点
   假设我们部署站点的端口是10000,那么部署成功以后我们就可以通过 http://xxx.xxx.xxx.xxx:10000去访问我们的Nuget服务了(下面则是我们部署成功后的效果图)
   搭建公司内部的NuGet服务器
搭建公司内部的NuGet服务器