Visual Studio 2005

About

The current version of the Visual Studio plugin is experimental and is meant as a proof of concept demonstrating that VS2005 can build .NET applications through Maven. It is being put out there to get early feedback on what developers want to see.

Installing

Follow the build instructions here: Building NMaven or configure your system to remotely download the Maven Visual Studio 2005 Installer Plugin

Now type

 mvn org.apache.maven.dotnet.plugins:maven-vsinstaller-plugin:install

This plugin will resolve (and download if needed) all of NMaven's dependencies and will create the Visual Studio addin file in the user home directory: ~\My Documents\Visual Studio 2005\Addins\NMaven.VisualStudio.AddIn.

Sample Generated Addin file:

<?xml version="1.0" encoding="utf-16"?>
<Extensibility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.microsoft.com/AutomationExtensibility">
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>8.0</Version>
  </HostApplication>
  <Addin>
    <Assembly>
        C:\Documents and Settings\shane\.m2\repository\NMaven\VisualStudio\NMaven.VisualStudio.Addin\0.14\NMaven.VisualStudio.Addin.dll
    </Assembly>
    <FullClassName>NMaven.VisualStudio.Addin.Connect</FullClassName>
    <FriendlyName>NMaven.VisualStudio.Addin</FriendlyName>
    <Description>NMaven provides Maven 2.x plugins to support building of .NET applications</Description>
    <LoadBehavior>0</LoadBehavior>
    <CommandLineSafe>0</CommandLineSafe>
    <CommandPreload>1</CommandPreload>
  </Addin>
</Extensibility>

Setting up a project

If you do not have a .NET Maven project setup, create a simple project:

 mvn archetype:create -DgroupId=<<myGroupid>>                               \
                      -DartifactId=<<myArtifactId>>                         \
                      -DarchetypeArtifactId=maven-archetype-dotnet-simple   \
                      -DarchetypeGroupId=org.apache.maven.dotnet            \
                      -DarchetypeVersion=0.14-SNAPSHOT

You will see the following project generated:

 .
  |-- src
  |   `-- main
  |       `-- csharp
  |           `-- Sample
  |               `-- MyApp.cs
   `-- pom.xml

Next install the solution:

 mvn install

To generate the solution and project files (csharp only), go to the directory containing the pom.xml and type

 mvn NMaven.Plugins:NMaven.Plugin.Solution.JavaBinding:Solution

Using Visual Studio

  • Startup Visual Studio 2005 by clicking on a generated solution file
  • Start the NMaven addin [Tool/NMaven Build System]. The addin will start and make a connection to an embedder jetty server hosting the maven embedder.
  • After a few moments you should see a window appear. Dock the window.
  • Click on a project file
  • Under options, click "Load Solution"
  • After a few moments you should see a frame appear containing a list of maven projects, by artifact ID. Right click on one of the projects to do a build. You will see the output within the output pane.

Debugging

When starting the adding, you may see an error message box:

The Add-in supporting this command could not be loaded. Do you wish to remove this command?

To get proper log messages, shutdown your IDE and go to the C:\Program Files\Microsoft Visual Studio 8\Common7\IDE directory . Type:

devenv /Log C:\tmp\VS2005.log /ResetAddin NMaven.VisualStudion.Addin

Go back through the steps that caused the error. Now look at your log file. The most common error is: "Unable to connect to the remote server" This means that the embedded server did not properly start up.

If the plugin loads, but you still encounter errors, check under the .m2/embedder-error-logs directory. You will see two log files: jetty-log.xml and the nmaven-embedder-log.xml. The jetty-log will tell you what port the jetty server starts on and the location of the war file. If the war file does not load correctly, jetty will output information to this log. This log will also tell you if the server started successfully.

 <record>
  <date>2007-07-30T17:35:37</date>
  <millis>1185842137390</millis>
  <sequence>0</sequence>
  <level>INFO</level>
  <class>org.apache.maven.dotnet.jetty.JettyStarter</class>
  <method>main</method>
  <thread>10</thread>
  <message>NMAVEN: Port = 8080,
  warFile = C:\Documents and Settings\shane\.m2\repository\org\apache\maven\dotnet\dotnet-service-embedder\0.14\dotnet-service-embedder-0.14.war</message>
</record>
<record>
  <date>2007-07-30T17:35:40</date>
  <millis>1185842140500</millis>
  <sequence>7</sequence>
  <level>INFO</level>
  <class>org.apache.maven.dotnet.jetty.JettyStarter</class>
  <method>main</method>
  <thread>10</thread>
  <message>NMAVEN: Successfully started server</message>
</record>

The nmaven-embedder-log.xml is useful for given information about why jetty itself does not start. It gives the location of the local repository that the embedder uses as well as the full classpath that jetty is using when it starts.

<record>
  <date>2007-07-30T17:35:37</date>
  <millis>1185842137078</millis>
  <sequence>0</sequence>
  <level>INFO</level>
  <class>org.apache.maven.dotnet.plugin.embedder.EmbedderStarterMojo</class>
  <method>execute</method>
  <thread>10</thread>
  <message>NMAVEN: Found local repository: Path =  C:\Documents and Settings\shane\.m2\repository</message>
</record>
<record>
  <date>2007-07-30T17:35:37</date>
  <millis>1185842137109</millis>
  <sequence>2</sequence>
  <level>INFO</level>
  <class>org.apache.maven.dotnet.plugin.embedder.EmbedderStarterMojo</class>
  <method>execute</method>
  <thread>10</thread>
  <message>[-Dport=8080,
  -DwarFile=C:\Documents and Settings\shane\.m2\repository\org\apache\maven\dotnet\dotnet-service-embedder\0.14\dotnet-service-embedder-0.14.war,
  -classpath, "C:\Documents and Settings\shane\.m2\repository\javax\servlet\jsp\jsp-api\2.1\jsp-api-2.1.jar";
  "C:\Documents and Settings\shane\.m2\repository\org\mortbay\jetty\jetty\6.1.5\jetty-6.1.5.jar";
  "C:\Documents and Settings\shane\.m2\repository\org\mortbay\jetty\jetty-util\6.1.5\jetty-util-6.1.5.jar";
  "C:\Documents and Settings\shane\.m2\repository\org\mortbay\jetty\jetty-embedded\6.1.5\jetty-embedded-6.1.5.jar";
  "C:\Documents and Settings\shane\.m2\repository\org\mortbay\jetty\servlet-api-2.5\6.1.5\servlet-api-2.5-6.1.5.jar";
  "C:\Documents and Settings\shane\.m2\repository\org\apache\maven\dotnet\dotnet-jetty\0.14\dotnet-jetty-0.14.jar",
  org.apache.maven.dotnet.jetty.JettyStarter]</message>
</record>

IDE And MavenEmbedder Interaction

The interaction starts when the developer loads the NMaven build addin (1). Visual Studio then starts up the MavenEmbedder as an external process running within a Jetty Server(2). Visual Studio starts up a logger port (3) that the MavenEmbedder can use to write log messages to.

The developer now issues a build command (4): compile, test, clean or install. Visual Studio does a SOAP call to the MavenEmbedder (5). The SOAP message contains the build command, the logger port and the file location of the pom.xml file to use during the build. The MavenEmbedder configures its logger to use a socket and connects to the Visual Studio logger port (6, 7). The MavenEmbedder issues the build command for each project contained within the pom.xml file (8) and starts building the project and writing the log messages to Visual Studio (9). Visual Studio takes the log messages and writes it out to the IDE output console (10) where the developer can see the build results (11).