Previously we have created an automated build file to clean, version, compile, zip-binaries and zip-source code.
If you’re now familiar with creating build files then you may want to catch up by reading these:
- Create a Build File for a Visual Studio Solution - MsBuild Series
- Mercurial Revision No to Version your AssemblyInfo - MsBuild Series
- Zipping Build Outputs using a Build File - MsBuld Series
1) NuPack Package Preparation
Before we start we need to get a few things in place.- We need the NuPack.exe utility
- We need a directory to keep our NuPack stuff.
- We need a NuPack manifest file
(NB: The best way to learn how to build nuspec packages (at the moment) is to look through the examples by downloading the codeplex repository here: http://nupackpackages.codeplex.com/SourceControl/list/changesets)
After downloading the following path should be valid:
- [project root]\tools\nupack\nupack.exe
- [project root]\NuPack\
- [project root]\NuPack\StickyBeak.nuspec
This file needs to conform to the nuspec file format found here: http://nupack.codeplex.com/documentation?title=Nuspec%20FormatNotice for now that we have hard coded the version number, later as part of the build we will replace this version number with the real version number.
Below is a sample for the StickyBeak project:
<?xml version="1.0" encoding="utf-8"?> <package> <metadata> <id>StickyBeak</id> <version>1.0.0.0</version> <authors> <author>Mark Kemper</author> <author>Jobping</author> </authors> <description>StickyBeak is a logging utility for asp.net websites which can log every request to your site. It provides similar features as IIS log files but provides additional logging information (which just isn’t possible with IIS logs) and easy viewing of logs via a admin page</description> <language>en-US</language> </metadata> </package>
Next I needed to copy some static files under the NuPack Directory. For StickyBeak I created the follow static content transforms
- [Project Root]\NuPack\Content\NLog.config.transform”
- [Project Root]\NuPack\Content\Web.Config.transform”
Once you have your NuPack directory setup just how you want it, its time to build the package using a build target.
2) NuPack Target
For building the NuPack package I followed these basic steps it the build- Copy everything from our “[Project Root]\NuPack” directory into “[Project Root]\Build\NuPack” . This sets up the static content required for the NuPack package.
- Copy the freshly built binaries from our output directory into “[Project Root]\Build\NuPack\Lib” – these files will become references when someone installs our package.
- Update the version number inside the Package specification file using a FileUpdate (regex) task
- Use a exec task to call the NuPack.exe executable and perform the packaging. NB: I set the working directory so the package will be created in the correct location.
The full target is shown below:
<Target Name="NuPack">
<PropertyGroup> <NuPackDestDir>$(BuildOutputDir)\NuPack</NuPackDestDir><NuPackDestSource>NuPack</NuPackDestSource></PropertyGroup> <ItemGroup> <NuPackFiles Include="$(NuPackDestSource)\**" /><NuPackLibFiles Include="$(BuildOutputDir)\Bin\**" /><NuPackPackageFile Include="StickyBeak*nupkg" /></ItemGroup> <Message Text="Setting up the $(NuPackDestDir) directory will all the necessary files to create our package"/> <Copy SourceFiles="@(NuPackFiles)" DestinationFiles="@(NuPackFiles->'$(NuPackDestDir)\%(RecursiveDir)%(Filename)%(Extension)')" /> <Copy SourceFiles="@(NuPackLibFiles)" DestinationFiles="@(NuPackLibFiles->'$(NuPackDestDir)\Lib\%(RecursiveDir)%(Filename)%(Extension)')" /> <FileUpdate Files="$(NuPackDestDir)\StickyBeak.nuspec" Regex="version>([^<]*)</version" ReplacementText="version>$(Major).$(Minor).$(Build).$(Revision)</version" /> <Message Text="Executing the NuPack.exe packager"/> <Exec WorkingDirectory="$(BuildOutputDir)" Command="..\Tools\NuPack\NuPack.exe ..\$(NuPackDestDir)\StickyBeak.nuspec"/> </Target>
3) Update Our Default Build
Now we can update default build task to create our NuSpec package after each successful build.<Target Name="Build" DependsOnTargets="Clean; VersionSolutionInfo; Compile; Zip-Source; Zip-Binaries; NuPack">That's it. We can now prepare our NuSpec package a the click of a button. The results of our build directory now look like this:
<Message Text="Clean, VersionSolutionInfo, Compile, Zip-Source, Zip-Binaries,NuPack
"/> </Target>
Resources:
- Main MsBulid File - Main build with targets : clean, compile & build. Imports all other build files.
- Version MsBuild File - Contains targets from a previous post (to auto version AssemblyInfo from mercurial)
- Zip MsBuild File - Contains targets from a previous post (to create zips)
- NuPack MsBuild File - Contains targets from this post (to create a nupack package).
- MSBuild Project File Schema Reference - Microsoft documents on MsBuild
This is the forth post in the MsBuild series.
- Create a Build File for a Visual Studio Solution - MsBuild Series
- Mercurial Revision No to Version your AssemblyInfo - MsBuild Series
- Zipping Build Outputs - MsBuild Series
- NuPack packaging - MsBuild Series
- NUnit Testing - MsBuild Series (coming later)
- Web Projects and AspNetComplier - MsBuild Series (coming later)
- Cruise Control - MsBuild Series (coming later)
4 comments:
I too believe that the NuPack using a Build File is the best option for building the MS Build Series.
If you are looking for a document generation system that you can call from .net, take a look at this dotnet document generation site. It has basic info on all the vendors. It makes for a great starting point
At first I was getting the following error:
error MSB4025: The project file could not be loaded. '<', hexadecimal value 0x3C, is an invalid attribute character. Line 75, position 74.
It fixed it by changing the '<' characters to '<'.
Hah, of course that happened. That would be <
Hey I my friends I tell you something can you give me answer The perk of deep linking 2.0 is that you will get better results on SERPs, if you manage to get the specific anchor text link on the backlink page which will be the inner page. Meaning: the backlink placed at www.onessite.com/inner_page_1 will pass more “link juice” than the one placed at www.onessite.com on the condition that both pages have the same PR and the same or almost the same amount of outbound links.
cheap link building plan
Post a Comment