在构建过程中自动创建NuGet软件包 [英] Automating creating NuGet package as part of build process

查看:83
本文介绍了在构建过程中自动创建NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要扩展的自动构建过程,因此我可以构建通过NuGet分发的库.当前,运行nuget.exe来创建软件包是手动操作.

I have an automated build process that I'd like to extend so I can build the libraries I am distributing via NuGet. Currently, running nuget.exe to create the packages is a manual operation.

设置VS 2010的最佳方法是什么,以使我的NuGet包(* .nupkg)文件成为发布"版本的最终结果?

请记住,对于某些软件包,我还有其他文件(内容和工具).而且,在大多数情况下,我将多个项目合并到单个NuGet包中,以支持.NET 4,Silveright和Phone 7.

Keep in mind that I have other files (content and tools) for some of the packages. And, in most cases, I have multiple projects merged into a single NuGet package to support .NET 4, Silveright and Phone 7.

(我需要澄清的是,现有的自动化"过程是一个简单的批处理文件运行程序,可使用命令行来构建解决方案.)

更新

我想刷新此讨论,因为该问题尚未解决.虽然提供的@pravin链接很有帮助,但并不能解决我在一个程序包中包含多个项目以及PowerShell脚本,配置和源代码转换等其他内容的事实.

I want to refresh this discussion because the issue has not been resolved. While the link @pravin supplied is helpful, it doesn't address the fact that I have multiple projects in a single package as well as other contents like PowerShell scripts, configuration and source code transformations, etc.

我可以使用的最佳示例是同时具有.NET 4和Silverlight 5版本的程序集.这些都分布在同一程序包中.我不能使用构建后事件来创建程序包,因为该程序包依赖于两个项目.

The best example I can use is an assembly that has both a .NET 4 and Silverlight 5 version. These are distributed in the same package. I cannot use a post-build event to create the package because the package is dependent upon TWO projects.

推荐答案

一个可行的方法是创建一个自定义MSBuild .proj文件.您可以在自定义脚本中定义几个目标,第一个在解决方案上执行编译的目标.要在编译之后执行的第二个目标将使用EXEC MSBuild任务来调用nuget.exe命令行实用程序.然后,您更新批处理文件运行器,以执行msbuild可执行文件,其中提供您的自定义项目文件作为参数.您可能已经在批处理脚本中使用了MSBuild,在这种情况下,这仅是参数交换的问题.您可以在解决方案的解决方案项目中包含您的自定义proj文件.如果这样做的话,您可以轻松地在Visual Studio中添加一个外部工具引用,以快速测试您的自定义脚本,以确保它像您希望的那样生成和生成了该软件包.

One thing that might work well is to create a custom MSBuild .proj file. You could define a couple targets in the custom script, the first to execute the compile on your solution. A second target to execute following compilation would use the EXEC MSBuild task to invoke the nuget.exe command line utility. Then, you update your batch file-runner to execute the msbuild executable supplying your custom project file as an argument. You might already be using MSBuild in your batch script, which in that case it would simply be a matter of argument swapping. You could include your custom proj file in the solution items of your solution. If you did that you could easily add an external tool reference in Visual Studio to quickly test out your custom script to make sure it was building and producing the package like you hope.

示例MSBuild

您可以以此为起点:

<Project DefaultTargets="Compile" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
    <PropertyGroup>
      <SolutionFile></SolutionFile>
      <NugetExecutable>C:\PathToNuget\nuget.exe</NugetExecutable>
      <NuspecFile></NuspecFile>
    </PropertyGroup>

    <Target Name = "Compile">
        <MSBuild Projects="$(SolutionFile)" Properties="Configuration=Release" />
    </Target>

    <Target Name = "Package">
    <!-- You could use the MSBuild Copy task here to move the compiled code into
           a structure that fits your desired package format -->
      <Exec Command="&quot;$(NugetExecutable)&quot; pack $(NuspecFile)" />
    </Target>
</Project>

然后您将这样称呼:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" Build.proj /p:SolutionFile=PathToSolution\App.sln;NuspecFile=foo.nuspec

这篇关于在构建过程中自动创建NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆