• [译]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" />。这时,你需要删除老版本的。

    1. 将要加入的包的 xxx.nupkg文件放到Packages文件夹下面,并将这些.nupkg文件的Build Action设为Content,将Copy to Output Directory设为Copy always
    2. 按Ctrl+F5启动网站。首页上会提供package feed URL。如果出现错误,检查web.config去除重复元素。
    3. 点击上图中的here超级链接,可查看已安装的包。
    4. 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.
    5. 一旦本地部署成功了,可以将应用发布到内部或者外部的服务器上。
    6. 一旦部署到了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

    <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。

  • 相关阅读:
    Kefa and Park
    分土地
    果园里的树
    分解质因数
    素数筛
    cantor的数表
    new一个二维数组
    基础练习 十六进制转八进制
    查函数功能
    concatenate函数
  • 原文地址:https://www.cnblogs.com/irocker/p/nuget-server.html
Copyright © 2020-2023  润新知