Visual Studio 2010 has been out for a few days now. For those of us lucky enough to have the freedom to upgrade our current projects to .NET 4.0, one potential drawback is that our builds stop working. If you are like us and using Continuous Integration with CC.NET and Nant, then hopefully this post will help you get your builds back on track.

First, open the file NAnt.exe.config and add the following node under nant/frameworks/platform. This framework node specifies the existence and location of .Net 4.0.

<framework
                  name="net-4.0"
                  family="net"
                  version="4.0"
                  vendor="MIcrosoft"
                  description="Microsoft .NET Framework 4.0"
                  sdkdirectory="${path::combine(sdkInstallRoot, 'bin')}"
                  frameworkdirectory="${path::combine(installRoot, 'v4.0.30319')}"
                  frameworkassemblydirectory="${path::combine(installRoot, 'v4.0.30319')}"
                  clrversion="4.0.20506"
                  >
                <runtime>
                  <probing-paths>
                    <directory name="lib/net/2.0" />
                    <directory name="lib/net/neutral" />
                    <directory name="lib/common/2.0" />
                    <directory name="lib/common/neutral" />
                  </probing-paths>
                  <modes>
                    <strict>
                      <environment>
                        <variable name="COMPLUS_VERSION" value="v4.0.20506" />
                      </environment>
                    </strict>
                  </modes>
                </runtime>
                <reference-assemblies basedir="${path::combine(installRoot, 'v4.0.20506')}">
                  <include name="Accessibility.dll" />
                  <include name="mscorlib.dll" />
                  <include name="Microsoft.Build.Engine.dll" />
                  <include name="Microsoft.Build.Framework.dll" />
                  <include name="Microsoft.Build.Utilities.dll" />
                  <include name="Microsoft.Vsa.dll" />
                  <include name="Microsoft.VisualBasic.dll" />
                  <include name="Microsoft.VisualBasic.Compatibility.dll" />
                  <include name="Microsoft.VisualBasic.Compatibility.Data.dll" />
                  <include name="System.Configuration.dll" />
                  <include name="System.Configuration.Install.dll" />
                  <include name="System.Data.dll" />
                  <include name="System.Data.OracleClient.dll" />
                  <include name="System.Data.SqlXml.dll" />
                  <include name="System.Deployment.dll" />
                  <include name="System.Design.dll" />
                  <include name="System.DirectoryServices.dll" />
                  <include name="System.dll" />
                  <include name="System.Drawing.Design.dll" />
                  <include name="System.Drawing.dll" />
                  <include name="System.EnterpriseServices.dll" />
                  <include name="System.Management.dll" />
                  <include name="System.Messaging.dll" />
                  <include name="System.Runtime.Remoting.dll" />
                  <include name="System.Runtime.Serialization.Formatters.Soap.dll" />
                  <include name="System.Security.dll" />
                  <include name="System.ServiceProcess.dll" />
                  <include name="System.Transactions.dll" />
                  <include name="System.Web.dll" />
                  <include name="System.Web.Mobile.dll" />
                  <include name="System.Web.RegularExpressions.dll" />
                  <include name="System.Web.Services.dll" />
                  <include name="System.Windows.Forms.dll" />
                  <include name="System.Xml.dll" />
                </reference-assemblies>
                <task-assemblies>
                  <!-- include MS.NET version-neutral assemblies -->
                  <include name="extensions/net/neutral/**/*.dll" />
                  <!-- include MS.NET 2.0 specific assemblies -->
                  <include name="extensions/net/2.0/**/*.dll" />
                  <!-- include MS.NET specific task assembly -->
                  <include name="NAnt.MSNetTasks.dll" />
                  <!-- include MS.NET specific test assembly -->
                  <include name="NAnt.MSNet.Tests.dll" />
                  <!-- include .NET 2.0 specific assemblies -->
                  <include name="extensions/common/2.0/**/*.dll" />
                </task-assemblies>
                <tool-paths>
                  <directory name="${path::combine(sdkInstallRoot, 'bin')}"
                  if="${property::exists('sdkInstallRoot')}" />
                  <directory name="${path::combine(installRoot, 'v2.0.50727')}" />
                  <directory name="${path::combine(installRoot, 'v3.0')}" />
                  <directory name="${path::combine(installRoot, 'v3.5')}" />
                </tool-paths>
                <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="supportsnowarnlist">true</attribute>
                    <attribute name="supportswarnaserrorlist">true</attribute>
                    <attribute name="supportskeycontainer">true</attribute>
                    <attribute name="supportskeyfile">true</attribute>
                    <attribute name="supportsdelaysign">true</attribute>
                    <attribute name="supportsplatform">true</attribute>
                    <attribute name="supportslangversion">true</attribute>
                  </task>
                  <task name="vbc">
                    <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="supportsdelaysign">true</attribute>
                    <attribute name="supportsplatform">true</attribute>
                    <attribute name="supportswarnaserrorlist">true</attribute>
                  </task>
                  <task name="jsc">
                    <attribute name="supportsplatform">true</attribute>
                  </task>
                  <task name="vjc">
                    <attribute name="supportsnowarnlist">true</attribute>
                    <attribute name="supportskeycontainer">true</attribute>
                    <attribute name="supportskeyfile">true</attribute>
                    <attribute name="supportsdelaysign">true</attribute>
                  </task>
                  <task name="resgen">
                    <attribute name="supportsassemblyreferences">true</attribute>
                    <attribute name="supportsexternalfilereferences">true</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>
                </tasks>
              </framework>

 

Second, in your actual build file, you need to specify the framework version for NAnt to use. This framework version points to the framework information that was added to NAnt.exe.config above. For instance, if the build file is MyProject.Build.xml, at the top of the file where the property elements are declared, simply add another property identical to the following:

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

There is another helpful post on this subject here; however, there is a problem in it and I recommend to use the configuration XML in this post instead.