zoukankan      html  css  js  c++  java
  • 在内部架设NuGet服务器

    在公司内部有很多基础框架或者基础组件,甚至对于使用SOA架构的公司来说,会有大量的业务组件的契约程序集,对于这些框架或组件的引用管理有的人使用源代码管理工具,但是NuGet相比源代码管理工具更方便:

    1) 安装和卸载:不需要手动添加和移除引用,不需要手动改写配置文件甚至是一些初始化服务的代码。版本升级也只需要执行一条命令。

    2) 打包:多文件打包,支持依赖管理等,使用的人没有繁琐的配置。

    对于官方的包,可以在http://www.nuget.org/ 找到,自己也可以提交包上去。但是如果不希望把包公开的话,可以在内部架设一个NuGet服务器。

    下面介绍一下基本步骤以及如何进行打包。

    1) 下载 NuGetServer.rar (包含源代码,改编自mceranski-nugetserver,找不到原始下载地址了)编译后,发布到内网服务器上。这个MVC3网站有几个功能:

    一是提供Nuget的服务,提供所有包的信息,供VS2010中NuGet包管理器使用

    二是提供了几个页面,可以上传包也可以浏览所有的包

    三是提供了一个web服务,可以供程序在编译后自动上传包

    2) 下载 Lib.rar (仅是可执行文件),解压缩到解决方案目录下的Lib目录中。这个压缩包里提供了两个程序:

    一是官网提供的NuGet.exe小工具,可以打包文件称nupkg

    二是自己写的一个上传包到NuGet服务端Web服务的小工具,这里是源代码,它会上传最新编译的那个包

    3) 配置需要打包的项目的属性:

    image

    IF NOT "$(ConfigurationName)"=="Release" EXIT /B 0
    IF NOT EXIST $(SolutionDir)ReleasePackages MD $(SolutionDir)ReleasePackages
    $(SolutionDir)Libs\NuGet.exe Pack $(ProjectDir)$(ProjectName).nuspec -o $(SolutionDir)ReleasePackages\
    $(SolutionDir)Libs\NuGetPackageUploader.exe $(SolutionDir)ReleasePackages\

    这段脚本完成的功能是:

    如果是Release方式编译的话,先创建ReleasePackages文件夹,然后调用NuGet.exe 打包,最后调用NuGetPackageUploader.exe 上传包

    4) 在项目中创建[项目名].nuspec,包描述文件:

    <?xml version="1.0" encoding="utf-8"?>
    <package>
      <metadata>
        <id>WcfExtension</id>
        <version>1.0.0.0</version>
        <title>WcfExtension</title>
        <authors>作者</authors>
        <projectUrl>项目地址</projectUrl>
        <description>A communication framework based on Wcf</description>
      </metadata>
      <files>
        <file src="bin\Release\*.dll" target="lib" />
        <file src="bin\Release\*.transform" target="content" />
      </files>
    </package>
    在这里,我们把所有的dll打入包,并且还把用于转换配置文件的transform文件打入包。

    为了自动在配置文件中增加节点,我们在项目文件下创建app.config.transform和web.config.transform,设置为:

    image

    文件内容和普通的配置文件无异:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
      </configSections>
      <appSettings>
        <add key="configservice_address" value="192.168.129.11:1888/WcfConfigService.svc" />
        <add key="logservice_address" value="192.168.129.12:1889/WcfLogService.svc" />
        <add key="redis_address" value="192.168.129.175" />
        <add key="redis_message_client_channel" value="WcfConfigClientChange"/>
        <add key="redis_message_service_channel" value="WcfConfigServiceChange"/>
      </appSettings>
      <unity configSource="unity.config" />
    </configuration>

    5) 以release编译项目之后,可以发现ReleasePackages中多了一个包,并且这个包会上传到远程的NuGet服务端。

    image

    如果没有上传成功,请检查NuGetPackageUploader.exe.config中的地址是否修改为你部署的服务端的地址。

    6) 在官网安装了VS2010的NuGet包管理器插件之后:

    image

    配置一下NuGet服务端地址应该就可以看到自己上传的所有包了:

    image

    如果你的网站部署到nuget.xxx.com,那么这里的地址填写nuget.xxx.com/nuget就可以了。

    找到包点击Install按钮就可以安装上这个组件了。

    打开包管理器控制台,输入get-help NuGet,可以看到其它的一些命令:

    ------------------        ----------------------------------------------
    Get-Package                Gets the set of packages available from the package source.

    Install-Package            Installs a package and its dependencies into the project.

    Uninstall-Package        Uninstalls a package. If other packages depend on this package,
                            the command will fail unless the –Force option is specified.

    Update-Package            Updates a package and its dependencies to a newer version.

    New-Package                Creates a new package when supplied with a Nuspec package specification file.

    Add-BindingRedirect        Examines all assemblies within the output path for a project and adds binding
                            redirects to the application (or web) configuration file where necessary.
                       
    Get-Project                Returns a reference to the DTE (Development Tools Environment) for the active
                            or specified project.

  • 相关阅读:
    firstresponder 后,键盘不显示
    performSelector
    setNeedsDisplay、setNeedsLayout 区别
    Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
    GCD介绍(一):基本概念和dispatch queues
    一些概念
    /mnt/sdcard /sdcard
    eclipse 导入已存在的工程文件出错
    ios 常用技巧
    ios nsstring去掉换行符
  • 原文地址:https://www.cnblogs.com/lovecindywang/p/2044301.html
Copyright © 2011-2022 走看看