首页 文章

为具有多个项目的解决方案创建nuget包

提问于
浏览
15

我们目前正在构建包含多个项目的解决方案 .

我们有这样的事情:

- Common
  - Logging
     - Logging.NLog
- Threading

所以Logging.NLog依赖于Logging,Logging on Common等 .

当我们打包Logging.NLog时,我希望nuget能够发现Loggin和Common dependecies .

此刻,我用Common创建了一个包,然后在Logging中我安装了包Common

install-package Common

但每当我对Common进行修改时,我都必须更新包,它们是由我们的连续集成系统(Hudson)创建的,所以当我们开发时它非常烦人 .

我想简单地有一个项目参考(添加引用 - >项目...),并且nuget无论如何都会发现依赖项 .

有没有办法实现它?

4 回答

  • 1

    计划feature针对此确切方案 .

    这显然是这样的:

    > nuget.exe pack proj.csproj -IncludeReferencedProjects
    

    它显然已经在几天前implemented,但有bugs still being ironed out .

    目前的功能允许:

    • 将几个项目的工件打包到一个nuget包中(通过递归遍历项目引用),

    要么

    • 如果引用的项目附带.nuspec文件,则创建对这些项目的关联包的nuget包引用 .

    功能请求一直追溯到1.5,但它一直在滑动 . 最近,它收集了足够的质量(请求),计划在Nuget 2.3发布 .

    发布计划为"End of April, 2013"固定版本2.3所以请继续关注 .
    (目前,最新的Nuget版本是2.2.1) .

  • 2

    目前无法完全按照您的要求进行操作,但以下内容可帮助您简化更新 .

    听起来您需要将nuspec文件添加到您的解决方案中 . 类似以下三个文件 . 请注意后两个中的依赖项 . 这些引用与[$ version $]相同的dll版本 . 这意味着当您运行以下命令时,它会更新所有三个,因为依赖项上的方括号需要特定版本的依赖包 .

    PM> update-package常见

    在Hudson中,您需要使用nuget pack命令(see Nuget command reference)执行这些nuspec文件,并在工件中包含生成的包,并将它们部署到您的本地nuget服务器 . 我会把它留给你 .

    您需要做的另一件事是确保所有程序集都获得相同版本的相同版本 . 同样,Hudson可以处理这个问题,或者您可以使用通用的AssemblyInfo文件 .

    Common.nuspec

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <version>$version$</version>
        <authors>Charles Ouellet</authors>
        <owners />
        <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
        <id>Common</id>
        <title>Common</title>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>full description here</description>
    </metadata>
    <files>
        <file src="..\Common\bin\Release\Common.dll" target="lib\net40" />
        <file src="..\Common\bin\Release\Common.pdb" target="lib\net40" />
    </files>
    </package>
    

    Logging.nuspec

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <version>$version$</version>
        <authors>Charles Ouellet</authors>
        <owners />
        <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
        <id>Logging</id>
        <title>Logging</title>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>full description here</description>
        <dependencies>
            <dependency id="Common" version="[$version$]" />
        </dependencies>        
    </metadata>
    <files>
        <file src="..\Logging\bin\Release\Logging.dll" target="lib\net40" />
        <file src="..\Logging\bin\Release\Logging.pdb" target="lib\net40" />
    </files>
    </package>
    

    Logging.NLog

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <version>$version$</version>
        <authors>Charles Ouellet</authors>
        <owners />
        <iconUrl>http://domain/Content/images/LOGO_32x32.png</iconUrl>
        <id>Logging.NLog</id>
        <title>Logging.NLog</title>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>full description here</description>
        <dependencies>
            <dependency id="Logging" version="[$version$]" />
        </dependencies>        
    </metadata>
    <files>
        <file src="..\Logging.NLog\bin\Release\Logging.NLog.dll" target="lib\net40" />
        <file src="..\Logging.NLog\bin\Release\Logging.NLog.pdb" target="lib\net40" />
    </files>
    </package>
    
  • 13

    我认为Charles意味着他希望NuGet自动将项目引用解析为包依赖项,如果所引用的项目也用于构造NuGet包,对吧?

    例:

    • 日志记录设置为生成NuGet包

    • Logging.Nlog设置为生成NuGet包

    • Logging.Nlog具有对Logging的项目引用 .

    • 生成的Logging.Nlog包应该依赖于生成的Logging包 .

    这也是我一直在寻找的东西,但遗憾的是我发现它目前还没有得到支持 . 它上面有一个work item,计划用于NuGet 1.7,但是还没有关于如何处理它的设计 .

  • 1

    这个帖子有一个很好的建议:NuGet and multiple solutions

    基本上,通过自己的发布生命周期,将公共组件分解为自己的解决方案 .

相关问题