[译]Nuget.Server

原文

NuGet.Server是一个包,可用于使一个ASP.NET应用host一个package feed 。

  1. 使用VS创建一个新的空WEB应用,添加Nuget.Server包。
  2. 配置应用的Packages文件夹,添加包。
  3. 部署应用到服务器上。

创建部署Nuget.Server ASP.NET应用

  1. 在VS中选择File > New > Project, 搜索"ASP.NET",选择ASP.NET Web Application (.NET Framework),设置Framework为".NET Framework 4.6":
  2. 给应用起一个合适的名字,点击OK,在下面的对话框中选择空白模板,点击OK。
  3. 右键项目,选择Manage NuGet Packages
  4. 在包管理器界面中,选择Browse选项,搜索安装最新版本的Nuget.Server包。 (还可在包控制台使用Install-Pacakge Nuget.Server安装Nuget.Server包。)
  5. 安装Nuget.Server会将空白的web应用转换成了一个package source。它安装了一起其他的包,在web应用的根目录创建了Packages文件夹,修改了web.config加上了一些配置。

    安装完Nuget.Server后,我们要检查下web.config文件。Nuget.Server可能没有覆盖已经存在于web.config中的元素,而是重复的创建了一个。这可能导致服务器内部错误"Internal Server Error" 。例如如果在安装Nuget.Server之前,你的web.config已经包含了<compilation debug="true" targetFramework="4.5.2" />,那么安装完Nuget.Server后,会多出一个<compilation debug="true" targetFramework="4.6" />。这时,你需要删除老版本的。

  6. 将要加入的包的 xxx.nupkg文件放到Packages文件夹下面,并将这些.nupkg文件的Build Action设为Content,将Copy to Output Directory设为Copy always
  7. 按Ctrl+F5启动网站。首页上会提供package feed URL。如果出现错误,检查web.config去除重复元素。
  8. 点击上图中的here超级链接,可查看已安装的包。
  9. The first time you run the application, NuGet.Server restructures the Packages folder to contain a folder for each package. This matches the local storage layout introduced with NuGet 3.3 to improve performance. When adding more packages, continue to follow this structure.
  10. 一旦本地部署成功了,可以将应用发布到内部或者外部的服务器上。
  11. 一旦部署到了http://<domain>,对应的package source的url为http://<domain>/nuget

配置Packages文件夹

在Nuget.Server 1.5 之后,可以在web.config中的appSetting/packagesPath来指定package文件夹:

<appSettings>
    <!-- Set the value here to specify your custom packages folder. -->
    <add key="packagesPath" value="C:\MyPackages" />
</appSettings>

packagesPath可以是绝对路径也可以是相对路径。
packagesPath没有设置或者其值为空白,那么默认的包文件夹为~/Packages

添加package

一旦Nuget.Server应用运行起来了,可以使用nuget push添加包。

安装完Nuget.Server,web.config会有一个appSetting/apiKey

<appSettings>
    <add key="apiKey" value="" />
</appSettings>

当没有apiKey或者其值为空的时候,push package到feed是禁用的。

设置apiKey并添加appSettings/requireApiKey设置其值为true

扫描二维码关注公众号,回复: 1066751 查看本文章
<appSettings>
        <!-- Sets whether an API Key is required to push/delete packages -->
    <add key="requireApiKey" value="true" />

    <!-- Set a shared password (for all users) to push/delete packages -->
    <add key="apiKey" value="" />
</appSettings>

可以设置requireApiKeyfalse。这样所有的人都可以push package了。

删除package

使用nuget delete命令从仓储中删除package。

可以设置web.config中的enableDelistingtrue启用delist。

猜你喜欢

转载自www.cnblogs.com/irocker/p/nuget-server.html
今日推荐