Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

visual studio 2010 - Automating creating NuGet package as part of build process

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.

What is the best way to setup VS 2010 so that my NuGet package (*.nupkg) file is the end result of a "Release" build?

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.

(I should clarify that the existing "automated" process is a simple batch-file runner that builds a solution using the command line.)

UPDATE

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Sample MSBuild

You can use this as a starting place:

<Project DefaultTargets="Compile" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
    <PropertyGroup>
      <SolutionFile></SolutionFile>
      <NugetExecutable>C:PathToNuget
uget.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>

You'd then call this like:

"C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe" Build.proj /p:SolutionFile=PathToSolutionApp.sln;NuspecFile=foo.nuspec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...