Build your webparts with NAnt

Well, first post for a long time now …

 

Following this post of my co-officer Renaud (himself following this one from Mads Nissen), I looked for a better way to build the CAB file, because I'm not an addict of his javascript hack. I thought it was possible, and I did.

 

The main problem when building the CAB file is how to generate the DDF file. How to get the content files of the project ? Of course by reading the CSPROJ file (nothing else than an XML file).

But the task can only get a single value, not a list of values. And more than one project have more than one content file. So, before coding a new task (not a bad thing to learn by the way), I googled a little bit of my time and found this post on the Serge's blog, inspired of this Richard Case post.

 

That's the solution : use task to get all file refs from CSPROJ file and write the ddf file accordingly. So :

 

  1. Create a temp directory
  2. Generate the DDF header lines in a file that you store in the temp dir with task <echo>, using attribute file. To change destination directory for the CAB file, change the .Set DiskDirectory1 parameter. Example : .Set DiskDirectory1=${project::get-base-directory()}/${build.dir}
  3. Get the compiled assembly (using <xmlpeek> task to get name and build location for the assembly from the CSPROJ ? Why not …), copy them into the temp directory and add the file name in the DDF file (use append attribute for task <echo> to avoid overwrite in the file).
  4. Use <xmllist> with xpath="//VisualStudioProject/CSHARP/Files/Include/File[@BuildAction='Content']/@RelPath", iterate in the list with the task <foreach> (delim="," if you didn't specify anything in the task <xmllist>), copy the corresponding file in the temp directory and add it to the DDF file.
  5. Now execute the makecab.exe with the task <exec> (using workingdir attribute can help).
  6. Delete the temp dir

 

It does the job. NAnt and community power ! Enjoy !

 

Note : A little bit of light info about the DDF file here.

 

Updated : This example may help.

Leave a Reply


Build your webparts with NAnt

Well, first post for a long time now …

 

Following this post of my co-officer Renaud (himself following this one from Mads Nissen), I looked for a better way to build the CAB file, because I'm not an addict of his javascript hack. I thought it was possible, and I did.

 

The main problem when building the CAB file is how to generate the DDF file. How to get the content files of the project ? Of course by reading the CSPROJ file (nothing else than an XML file).

But the task can only get a single value, not a list of values. And more than one project have more than one content file. So, before coding a new task (not a bad thing to learn by the way), I googled a little bit of my time and found this post on the Serge's blog, inspired of this Richard Case post.

 

That's the solution : use task to get all file refs from CSPROJ file and write the ddf file accordingly. So :

 

  1. Create a temp directory
  2. Generate the DDF header lines in a file that you store in the temp dir with task <echo>, using attribute file. To change destination directory for the CAB file, change the .Set DiskDirectory1 parameter. Example : .Set DiskDirectory1=${project::get-base-directory()}/${build.dir}
  3. Get the compiled assembly (using <xmlpeek> task to get name and build location for the assembly from the CSPROJ ? Why not …), copy them into the temp directory and add the file name in the DDF file (use append attribute for task <echo> to avoid overwrite in the file).
  4. Use <xmllist> with xpath="//VisualStudioProject/CSHARP/Files/Include/File[@BuildAction='Content']/@RelPath", iterate in the list with the task <foreach> (delim="," if you didn't specify anything in the task <xmllist>), copy the corresponding file in the temp directory and add it to the DDF file.
  5. Now execute the makecab.exe with the task <exec> (using workingdir attribute can help).
  6. Delete the temp dir

 

It does the job. NAnt and community power ! Enjoy !

 

Note : A little bit of light info about the DDF file here.

 

Updated : This example may help.

Leave a Reply