Configuring Toolchains

By default NMaven uses the .NET executables on the path (for example, by starting a "SDK Command Prompt" session from the Windows Start Menu). To configure a particular toolchain to use, or to avoid the path configuration requirement you need to configure a Maven toolchain.

Toolchains are a new feature in Maven 2.0.9 and above. For more information about the feature in general, see Using Toolchains.

There are two steps to this: adding the toolchain plugin to your project (or a common parent), and creating a ~/.m2/toolchains.xml file (alongside your settings.xml file). The following examples show the configuration for the currently available toolchains.

Microsoft Toolchain

For Microsoft builds you will need both Microsoft .NET Framework (1.1+) *and* NET Framework SDK.

To use the Microsoft SDK, configure the Toolchains plugin like the following:

 <build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-toolchains-plugin</artifactId>
       <version>1.0-SNAPSHOT</version>
       <executions>
         <execution>
           <phase>validate</phase>
           <goals>
             <goal>toolchain</goal>
           </goals>
         </execution>
       </executions>
       <configuration>
         <toolchains>
           <dotnet>
             <vendor>MICROSOFT</vendor>
           </dotnet>
         </toolchains>
       </configuration>
     </plugin>
   </plugins>
 </build>  

This will select the MICROSOFT vendor from the toolchains file. This requires adding configuration such as the following to your ~/.m2/toolchains.xml file:

<?xml version="1.0" encoding="UTF8"?>

<toolchains>
  <toolchain>
    <type>dotnet</type>
    <provides>
      <frameworkVersion>2.0</frameworkVersion>
      <vendorVersion>2.0.50727</vendorVersion>
      <vendor>MICROSOFT</vendor>
      <id>.NET Framework 2.0</id>
    </provides>
    <configuration>
      <csharpCompiler>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe</csharpCompiler>
      <nunitConsole>C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe</nunitConsole>
      <installRoot>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727</installRoot>
      <sdkInstallRoot>C:\Program Files\Microsoft.NET\SDK\v2.0</sdkInstallRoot>
    </configuration>
  </toolchain>
</toolchains>

Mono Toolchain

For Mono builds, you will need Mono (tested with 1.2.3.1+).

To use the Mono SDK, configure the Toolchains plugin like the following:

 <build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-toolchains-plugin</artifactId>
       <version>1.0-SNAPSHOT</version>
       <executions>
         <execution>
           <phase>validate</phase>
           <goals>
             <goal>toolchain</goal>
           </goals>
         </execution>
       </executions>
       <configuration>
         <toolchains>
           <dotnet>
             <vendor>MONO</vendor>
           </dotnet>
         </toolchains>
       </configuration>
     </plugin>
   </plugins>
 </build>  

This will select the MONO vendor from the toolchains file. This requires adding configuration such as the following to your ~/.m2/toolchains.xml file:

<?xml version="1.0" encoding="UTF8"?>

<toolchains>
  <toolchain>
    <type>dotnet</type>
    <provides>
      <frameworkVersion>2.0</frameworkVersion>
      <vendorVersion>1.9.1</vendorVersion>
      <vendor>MONO</vendor>
      <id>Mono 1.9.1</id>
    </provides>
    <configuration>
      <csharpCompiler>C:\Program Files\Mono-1.9.1\lib\mono\1.0\mcs.exe</csharpCompiler>
      <nunitConsole>C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe</nunitConsole>
      <installRoot>C:\Program Files\Mono-1.9.1</installRoot>
      <sdkInstallRoot>C:\Program Files\Mono-1.9.1\lib\mono\2.0</sdkInstallRoot>
    </configuration>
  </toolchain>
</toolchains>