views:

1347

answers:

8

I run an ASP.NET website solution with a few other projects in it. I've known that MSBuild projects are capable of this, but is it the best way? Are they easy to create? Is nAnt, CruiseControl.NET or any other solution better?

When I build the site (using Web Deployment Projects), can I automate part of the build so that it does not copy certain folders from the project into the Release folder? For instance, I have folders with local search indexes, images and other content part of the folder, but I never need or upload those when deploying the project.

I'm also looking toward this type of solution to automatically increment build and version numbers.

A: 

CruiseControl.NET solves a different problem (continuous integration) ... however, I've had great success with NAnt for specifically what you're asking. There's a learning curve, but once you get proficient you'll wonder how you ever got along w/o it.

xanadont
+1  A: 

You can set the Build Action/Copy to Output Directory property on individual files (select the file and hit F4 to open the properties window) to control what happens to them during build, but not for folders. This could probably be automated with a (pre) build task if you don't want to do it manually.

Alternatively, you can exclude these folders from the project (right click and 'exclude from project'); they'll still be there ("show all files" in solution explorer), but they won't be included when building the project.

Fredrik Kalseth
A: 

In addition to @Fredrik's tip about setting project items to "Copy to Output Directory", you can also specify a post-build action in the project's properties in the Build tab and include CMD commands like copy.exe and move.exe.

Mark Cidade
A: 

@Frederik, I'm not seeing this option at all. I choose files and go to the "Web File Properties" and the only options I have are File Name and Full Path.

I see this option for files in Class Libraries and other types of project, but not the website. I don't know why there are 2 types, but there is a difference between an ASP.NET Web Application and an ASP.NET Website. One uses a project file and the other is just a folder location on disk.

@marxidad, there is a similar issue here. I have known about these post and pre build commands you can set, but they are not available for the ASP.NET websites, only ASP.NET Web Applications. I hoped I could do this under the Solution properties, but no go.

It is looking like I will need to use an MSBuild project or Nant?

MaseBase
A: 

We use FinalBuilder to automate a bunch of post build / pre build tasks. There's also a web interface so you can kick off builds (or push websites) by logging in to the web site and clicking a button.

http://www.finalbuilder.com/

Michael Pryor
A: 

Can't you edit the Web Deployment project's MSBuild file for it to do what you want?

Mark Cidade
+2  A: 

MaseBase, you can use Web Deployment Projects to build and package Web Sites. We do that all the time for projects with a web application aspect. After you assign a WDP to a Web Site, you can open up the .wdproj file as plain-text XML file. At the end is a commented section of MSBuild targets that represent the sequence of events that fire during a build process.

<!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
Other similar extension points exist, see Microsoft.WebDeployment.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="BeforeMerge">
</Target>
<Target Name="AfterMerge">
</Target>
<Target Name="AfterBuild">
</Target>
-->

You can uncomment the targets you want (e.g. "AfterBuild") and insert the necessary tasks there to carry out your repeated post-build activities.

icelava
+6  A: 

Here's an example of a Web Deployment Project scripting this sort of task in the .wdproj file:

  <Target Name="AfterBuild">
    <!-- ============================ Script Compression============================ -->
    <MakeDir Directories="$(OutputPath)\compressed" />
    <Exec Command="java -jar c:\yuicompressor-2.2.5\build\yuicompressor-2.2.5.jar --charset UTF-8 styles.css -o compressed/styles.css" WorkingDirectory="$(OutputPath)" />
    <Exec Command="move /Y .\compressed\* .\" WorkingDirectory="$(OutputPath)" />
    <RemoveDir Directories="$(OutputPath)\sql" />
    <Exec Command="c:\7zip-4.4.2\7za.exe a $(ZipName).zip $(OutputPath)\*" />
  </Target>

This would allow you to delete a folder.

(I suspect that if you wanted to not have the folder copy over at all, the solution file would be the place to specify that, though I haven't had to use that.)

Chris
Wow, this is SO much easier than I expected! Awesome thanks!
MaseBase