November 2004 - Posts

Well, I had recently complained about some of the pre-publishing hype for McConnell's Code Complete, 2nd Edition.  Every book deserves its chance, so I picked up a copy.

My conclusion?  For too many pages, I felt like I was reading the first edition.  This book is pretty good, but I don't really know if it's worth reading if you've already got the first edition. 

McConnell's treatise on the proper placement of brackets went on for entirely too many pages.  I thought my eyes would bleed if he mentioned indentation structure one more time!

I readily admit that I am a fan of McConnell's Rapid Development. However, Code Complete will be busy gathering dust on my bookshelf.

I couldn't seem to find a way to update the Path environment variable using the 'stable' build of nAnt.  Setting sys.env.Path doesn't update the system environment variable, though the ${sys.env.Path} property will appear to be updated.  This can be somewhat confusing.

So, I've written a target, instead.  This "updatepath" target will update the path for the length of the nAnt build.  Set the "build.appendpath" property before calling this target, and be certain to call the <sysinfo/> task as well. 

A similar method could be used for any environment variable:

 

<target name="updatepath">
   
<script language="C#"> 
   
<code><![CDATA[

   public static void ScriptMain
(Project project)
   
{
      string currentPath = project.Properties[
"sys.env.Path"];
      
      // make certain that there is a trailing semicolon
      if
(!(currentPath.EndsWith(";"))) currentPath += ";";

      string updatedPath = currentPath
+ project.Properties["build.appendpath"];
      
SetEnvironmentVariable("Path", updatedPath);
   }

   [ System.Runtime.InteropServices.DllImport( "kernel32") ]
   public static extern bool SetEnvironmentVariable( string EnvironmentVariable, string EnvironmentValue );

      ]]></code>
   
</script>
</target>

More Posts