Click here to Skip to main content
Click here to Skip to main content
Go to top

Maven Build for .NET Application

, 18 Mar 2011
Rate this:
Please Sign up or sign in to vote.
How to build a .NET application using Maven

Introduction

This article describes how to perform the .NET application build in Maven tool. The intent of this article is to tell you how to go about doing a full command-line build of .NET application using Maven. You first need to install the prerequisite application, listed here.

Prerequisites

The following applications are used by the different goals, but This article describes only .NET application build and fxcop reports.

Application Usage Version Download site
MSBuild .NET sdk install dir 2.0, 3.5 http://msdn.microsoft.com/en-us/netframework/aa569263.aspx
Fx Cop .NET code quality reports 1.36 + http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en
Maven To build Run Maven POM 2.2.1 http://maven.apache.org/docs/2.2.1/release-notes.html

The following changes are required after the installation. After the SDK 7 is installed, we need to explicitly run Fxcop application. It will be available in the following location: C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\FXCop and run the fxcop application.

The following environment variables need to be set.

Variable Name Path
FXCOP_HOME C:\Program Files\Microsoft FxCop 1.35
JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
MAVAN_HOME C:\Bin\apache-maven-2.2.1\bin
PATH* Append : %JAVA_HOME%\bin;

Remember to restart the computer after changing the value of the SYSTEM PATH.

Configure Maven to Run

To configure Maven plugin to run, you need to edit the setting.xml. Open the file from c:\bin\apache-maven-2.2.1\conf\settings.xml and make the change (for your case, location may differ):

  1. Change Maven location repository, otherwise it will be downloaded in your document setting \ .m2... or <localRepository>C:\maven_repository</localRepository>.
  2. Change the Proxy setting according to your organization proxy config example: include the following code to proxy section and change the domain name and IP address:
    <proxy> 
      <active>true</active> 
      <protocol>http</protocol> 
      <host>http.proxy.domain.com</host> 
      <port>8000</port> 
      <nonProxyHosts>localhost|*.domain.com|0.0.0.1</nonProxyHosts> 
    </proxy>
  3. Include the .NET Profile into the profiles section example:
    <profile> 
      <id>dotnet</id> 
      <activation> 
        <activeByDefault>true</activeByDefault> 
      </activation> 
    </profile>
  4. Add the following code to Properties section:
    <properties> 
      <dotnet.2.0.sdk.directory>
        C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727
      </dotnet.2.0.sdk.directory> 
      <dotnet.3.5.sdk.directory>
        C:/WINDOWS/Microsoft.NET/Framework/v3.5
      </dotnet.3.5.sdk.directory> 
      <dotnet.4.0.sdk.directory>
        C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319
      </dotnet.4.0.sdk.directory> 
      <fxcop.directory>
        c:/Program Files/Microsoft FxCop 1.36
      </fxcop.directory> 
    </properties>

Build the .NET project in the command project with a few modifications to the pom files.

Project Parent Pom

<?xml version="1.0" encoding="utf-8"?>
<project xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
<groupId>MavenBuildTesting</groupId>
<artifactId>MavenBuildTesting-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <visual.studio.solution>MavenBuildTesting.sln</visual.studio.solution>
    <visual.test.project.pattern>*.Tests</visual.test.project.pattern>
    <dotnet.tool.version>3.5</dotnet.tool.version>
    <sonar.language>cs</sonar.language>
</properties>

<build>
    <plugins>
    <plugin>
        <groupId>org.codehaus.sonar-plugins.dotnet</groupId>
        <artifactId>maven-dotnet-plugin</artifactId>
        <extensions>true</extensions>
    </plugin>

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <configuration>
            <language>cs</language>
        </configuration>
        </plugin>
    </plugins>
</build>
</project>

The above file needs to be created where the project solution is present and below the file, you need to create where the project file is present.

Project Child Pom

<?xml version="1.0" encoding="utf-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://maven.apache.org/POM/4.0.0">
  <parent>
   <groupId>MavenBuildTesting</groupId>
    <artifactId>MavenBuildTesting-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>MavenBuildTesting</artifactId>
  <packaging>sln</packaging>
</project>

Please ensure that you build and install the parent first (from the parent directory).
Start -> Run -> cmd root to sample project:

C:\MavenBuildTesting\mvn dotnet:clean dotnet:compile install 

Then build and run the goals on the child:

C:\MavenBuildTesting\MavenBuildTesting>mvn dotnet:clean dotnet:compile dotnet:fxcop 

After the successful Maven task, you will be able to see the executable available in the obj directory or project bin release.

If you have any further issues building .NET with Maven, please let me know.

History

  • 18th March, 2011: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rajamohan.Rajendran
Technical Lead
India India
No Biography provided

Comments and Discussions

 
Questionsample code doesn't work....what's changed? PinmemberMember 826232623-Sep-11 6:16 
AnswerRe: sample code doesn't work....what's changed? PinmemberRajamohan.Rajendran25-Sep-11 17:18 
GeneralRe: sample code doesn't work....what's changed? PinmemberMember 826232626-Sep-11 8:37 
AnswerRe: sample code doesn't work....what's changed? PinmemberRajamohan.Rajendran26-Sep-11 17:36 
GeneralRe: sample code doesn't work....what's changed? PinmemberMember 82623265-Oct-11 10:08 
General[My vote of 1] good idea (possibly), bad execution PinmemberTieske811-Apr-11 11:13 
GeneralExciting! PinmemberJimBlaney18-Mar-11 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 18 Mar 2011
Article Copyright 2011 by Rajamohan.Rajendran
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid