One of the benefits about building with NAnt is being able to flip the switch and start targeting a different compiler, without having to switch to the latest version of Visual Studio. Although, you wont get the intellisense provided by studio for new features.
So today we flipped the switch on a project at work, from targeting the C# 2.0 compiler to the C# 3.0 compiler. We haven’t started leveraging any of the new functionality available in the new compiler but at least we know we can start.
So to flip the switch you’ll need to update your “nant.exe.config” file to include the .NET Framework version 3.5. Remember with this release we got a new version of the .NET Framework assemblies, a new C# 3.0 compiler but we’re still running it all in the 2.0 version of the CLR.
The new xml element to add to your “Nant.exe.config” file looks something like this:

<framework
      name="net-3.5"
      family="net"
      version="3.5"
      description="Microsoft .NET Framework 3.5"
      runtimeengine=""
      sdkdirectory="${path::combine(sdkInstallRoot, 'bin')}"
      frameworkdirectory="${path::combine(installRoot, 'v3.5')}"
      frameworkassemblydirectory="${path::combine(installRoot, 'v2.0.50727')}"
      clrversion="2.0.50727">
      <task-assemblies>
          <!-- include .NET specific assemblies -->
          <include name="tasks/net/*.dll" />
          <!-- include .NET 2.0 specific assemblies -->
          <include name="tasks/net/2.0/**/*.dll" />
          <!-- include Microsoft.NET specific task assembly -->
          <include name="NAnt.MSNetTasks.dll" />
          <!-- include Microsoft.NET specific test assembly -->
          <include name="NAnt.MSNet.Tests.dll" />
      </task-assemblies>
      <project>
          <readregistry
              property="installRoot"
              key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
              hive="LocalMachine" />
          <readregistry
              property="sdkInstallRoot"
              key="SOFTWARE\Microsoft\.NETFramework\sdkInstallRootv2.0"
              hive="LocalMachine"
              failonerror="false" />
      </project>
      <tasks>
          <task name="csc">
              <attribute name="exename">csc</attribute>
              <attribute name="supportsnowarnlist">true</attribute>
              <attribute name="supportswarnaserrorlist">true</attribute>
              <attribute name="supportskeycontainer">true</attribute>
              <attribute name="supportskeyfile">true</attribute>
              <attribute name="supportsplatform">true</attribute>
              <attribute name="supportslangversion">true</attribute>
          </task>
          <task name="vbc">
              <attribute name="exename">vbc</attribute>
              <attribute name="supportsdocgeneration">true</attribute>
              <attribute name="supportsnostdlib">true</attribute>
              <attribute name="supportsnowarnlist">true</attribute>
              <attribute name="supportskeycontainer">true</attribute>
              <attribute name="supportskeyfile">true</attribute>
              <attribute name="supportsplatform">true</attribute>
              <attribute name="supportswarnaserrorlist">true</attribute>
          </task>
          <task name="jsc">
              <attribute name="exename">jsc</attribute>
              <attribute name="supportsplatform">true</attribute>
          </task>
          <task name="vjc">
              <attribute name="exename">vjc</attribute>
              <attribute name="supportsnowarnlist">true</attribute>
              <attribute name="supportskeycontainer">true</attribute>
              <attribute name="supportskeyfile">true</attribute>
          </task>
          <task name="resgen">
              <attribute name="exename">resgen</attribute>
              <attribute name="supportsassemblyreferences">true</attribute>
              <attribute name="supportsexternalfilereferences">true</attribute>
          </task>
          <task name="al">
              <attribute name="exename">al</attribute>
          </task>
          <task name="delay-sign">
              <attribute name="exename">sn</attribute>
          </task>
          <task name="license">
              <attribute name="exename">lc</attribute>
              <attribute name="supportsassemblyreferences">true</attribute>
          </task>
          <task name="ilasm">
              <attribute name="exename">ilasm</attribute>
          </task>
          <task name="ildasm">
              <attribute name="exename">ildasm</attribute>
          </task>
      </tasks>
  </framework>

To flip the switch you can either override the nant setting in your build file …

<property name="nant.settings.currentframework" value="net-3.5" />

or you can change the default target framework in the “nant.exe.config” file.

<platform name="win32" default="net-3.5">

Source Nant.exe.config

comments powered by Disqus