Wednesday, January 24, 2007

ASP.NET 2.0: Using .refresh files from NAnt

I'm moving more and more towords building with NAnt, even for web applications. Based on some work done by Ewout from TallApplications I'm trying to develop a customizable NAnt build script for .NET 2.0 web applications. One of the things that was bothering me is that the aspnet_compiler tool (used to precompile sites) doesn't use the .refresh files used by Visual Studio 2005 to keep referenced assemblies up to date. It should be no problem to process these files with NAnt though; all they contain is the relative path to the referenced assembly in plain text. Google doesn't give quick results on this, so I went to work. Being a bit of newbie to NAnt build scripts it didn't take long to come up with this:
<!-- Refresh referenced assemblies -->
<foreach item="File" property="filename">
       <include name="${proddir}\bin\*.refresh" />
    <loadfile file="${filename}" property="RefreshFile" />
    <echo message="Refreshing ${RefreshFile}"/>
    <regex input="${RefreshFile}" pattern="^(?<BaseFile>.*)\.dll"/>
    <copy todir="${proddir}\bin" verbose="true" flatten="true">
          <include name="${proddir}\${BaseFile}.dll"/>
          <include name="${proddir}\${BaseFile}.xml"/>
          <include name="${proddir}\${BaseFile}.pdb"/>
Only requirement is that you set the proddir variable to the root folder of the site.


Anonymous said...

I just found this when I was looking to resolve some .refresh files in a build. It worked great. Thanks.

Minneapolis, MN

Marnix said...

Instead of resolving the .refresh files with NAnt I now use Microsoft's web deployment projects which are supported by msbuild and can therefore be invoked using the <msbuild> task in NAnt. This makes the automated build process easier to manage and closer to the development build process.