搭建公司内部的NuGet服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建公司内部的NuGet服务器相关的知识,希望对你有一定的参考价值。

1.  创建NuGet项目
     (注意:解决方案名称可以自定义为其他的名称)
      技术分享

  

2.   安装NuGet Server
      在 “NuGetServer” 项目上,右键选择 “管理NuGet程序包” ,选择 “联机” ,右上角搜索框中输入“NuGet.Server”  Enter,在搜索结果中选择 NuGet.Server 项,进行安装即可(如下图所示)。
      注意:如果安装最后,提示 替换 Web.config ,请选择“全是”。
      技术分享

 

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 Package Explorer来访问的时候也许要填入我们预先设置好的密钥才能够进行访问)
    
技术分享
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!--  For more information on how to configure your ASP.NET application, please visit  http://go.microsoft.com/fwlink/?LinkId=169433  -->
 3 <configuration>
 4   <appSettings>
 5     <!-- Determines if an Api Key is required to push\\delete packages from the server.  -->
 6     <add key="requireApiKey" value="true" />
 7 
 8     <!-- 
 9     Set the value here to allow people to push/delete packages from the server.
10     NOTE: This is a shared key (password) for all users.
11     -->
12     <add key="apiKey" value="ChinaNet910111" />
13     <!--
14     Change the path to the packages folder. Default is ~/Packages.
15     This can be a virtual or physical path.
16     -->
17     <add key="packagesPath" value="~/Packages" />
18 
19     <!--
20     Set allowOverrideExistingPackageOnPush to false to mimic NuGet.orgs behaviour (do not allow overwriting packages with same id + version).
21     -->
22     <add key="allowOverrideExistingPackageOnPush" value="false" />
23 
24     <!--
25     Set ignoreSymbolsPackages to true to filter out symbols packages. Since NuGet.Server does not come with a symbol server,
26     it makes sense to ignore this type of packages. When enabled, files named `.symbols.nupkg` or packages containing a `/src` folder will be ignored.
27     
28     If you only push .symbols.nupkg packages, set this to false so that packages can be uploaded.
29     -->
30     <add key="ignoreSymbolsPackages" value="true" />
31 
32     <!--
33     Set enableDelisting to true to enable delist instead of delete as a result of a "nuget delete" command.
34     - delete: package is deleted from the repositorys local filesystem.
35     - delist: 
36       - "nuget delete": the "hidden" file attribute of the corresponding nupkg on the repository local filesystem is turned on instead of deleting the file.
37       - "nuget list" skips delisted packages, i.e. those that have the hidden attribute set on their nupkg.
38       - "nuget install packageid -version version" command will succeed for both listed and delisted packages.
39         e.g. delisted packages can still be downloaded by clients that explicitly specify their version.
40     -->
41     <add key="enableDelisting" value="false" />
42 
43     <!--
44     Set enableFrameworkFiltering to true to enable filtering packages by their supported frameworks during search.
45     -->
46     <add key="enableFrameworkFiltering" value="false" />
47 
48     <!--
49     When running NuGet.Server in a NAT network, ASP.NET may embed the ervers internal IP address in the V2 feed.
50     Uncomment the following configuration entry to enable NAT support.
51     -->
52     <!-- <add key="aspnet:UseHostHeaderForRequestUrl" value="true" /> -->
53   </appSettings>
54   <system.web>
55     <httpRuntime maxRequestLength="31457280" />
56     <compilation debug="true" />
57   </system.web>
58   <system.serviceModel>
59     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
60   </system.serviceModel>
61   <system.webServer>
62     <staticContent>
63       <mimeMap fileExtension=".nupkg" mimeType="application/zip" />
64     </staticContent>
65     <modules runAllManagedModulesForAllRequests="true">
66     </modules>
67   </system.webServer>
68 </configuration>
web.config

 

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

 

以上是关于搭建公司内部的NuGet服务器的主要内容,如果未能解决你的问题,请参考以下文章

VS2017搭建Nuget服务器 (摘抄winnywin博客)

如何在nuget上传自己的包+搭建自己公司的NuGet服务器(新方法)

搭建私有Nuget服务

在内部架设NuGet服务器(转)

使用图形化界面打包自己的类库

NuGet学习笔记2——使用图形化界面打包自己的类库