Migrate .NET applications from Visual Studio to Eclipse

The Emonic plug-in and NAnt give .NET and C# capability to Eclipse

Eclipse supports Java™ and other programming languages with ease. But until recently, it was difficult to build, run, and debug C# projects with Eclipse. This article shows how to use Eclipse Mono Integration (Emonic) and NAnt, which are the most active C# and .NET toolkits available for Eclipse. This article was written for developers with a working knowledge of .NET, a familiarity with Eclipse, and a need for an effective way to work with C# and .NET in Eclipse.

Applications built with C# typically run in the .NET Framework, which is deployed on Windows® desktop, server, and mobile operating systems (see the sidebar "C# and .NET in a nutshell"). Though the Eclipse Platform provides the C Development Toolkit (CDT) to support C and C++ development, it cannot be used for C# development. Several Eclipse plug-ins work with the .NET Framework, but not all support the latest version, which, as of this writing, is V3.5.

This article shows how to use Emonic, which is a fully functional C# environment for the Eclipse Platform. Although the Emonic developers provide documentation that introduce installing and creating the project, working with an existing C# project is tricky if you follow the manual. This article will help you install, build, and run a C# project without any prior knowledge of it. We will use NAnt for the automatic building and running a .NET project. This article will also show how to migrate existing Visual Studio® projects using sample projects.

Introduction to Emonic and NAnt

Emonic at a glance

Emonic is an Eclipse plug-in that allows you to build C# programs with Mono or the Microsoft .NET Framework. You can use this plug-in to create C# projects using a project wizard. Figure 1 shows a C# project with the Emonic plug-in.

Figure 1. Example C# project with the Emonic plug-in
Example C# project with the Emonic plug-in
Example C# project with the Emonic plug-in

NAnt at a glance

Although the Emonic provides a project wizard, editor, auto-builder, launcher, and tutorial showing how to use all four, I struggled with building and launching applications using Emonic alone. That struggle prompted a search for an easy-to-use build tool that works with Emonic and notes that grew into this article. Here, I introduce the NAnt build tool and show how to import an existing C# project into an Eclipse workspace.

NAnt is a free .NET build tool that operates in a manner similar to Ant. NAnt supports .NET Framework V1.0 through V3.5. We will use NAnt V0.86 beta 1, which is the current release, and show how it can help you build and launch applications.

System requirements

You will need the following:

  • Eclipse V3.1 or later — We used Eclipse Europa here.
  • .NET V2.0 SDK — This means you must work in a Windows environment. As mentioned in "C# and .NET in a nutshell," open source developers have recreated much of the .NET Framework biosphere — but not all of it. Since the aim of this article is to show how to develop C# applications in Eclipse and not how to develop C# applications with Mono, DotGNU, or Rotor, we will leave those tasks as exercises for advanced readers.
  • NAnt V0.86 beta 1
  • Emonic
  • Microsoft .NET Framework V2.0 SDK samples

See Related topics for downloads.

Installing the Emonic plug-in and NAnt

Installing the Emonic plug-in

There are two methods for installing Emonic: updating Eclipse at an update site or downloading it from SourceForge. We use the update site in this example. Here are the steps: Menu: Help > Software Update > Find and Install > Search for new features to install. Click on New Remote site and input

After installing the Emonic plug-in and restarting Eclipse, you can use a project wizard to create a blank C# project. Figure 2 shows a Wizard to create C# project in Eclipse.

Figure 2. .NET create-project wizard in Eclipse
.NET create-project wizard in Eclipse
.NET create-project wizard in Eclipse

Download and install NAnt

The NAnt V0.86 beta1 is the latest build. Download it from SourceForge, unzip, and either install it in a customary place or set the NAnt directory to your path variables.

Import .NET sample projects

Download the Microsoft .NET Framework V2.0 SDK samples from MSDN and unzip them. The samples includes many sample projects (Visual Basic, C#, etc.). In this article, we will use the WebClientSample found in Technologies\Networking\WebClientSample\CS.

Project structure

Figure 3 shows a C# project structure in explorer view.

Figure 3. C# project structure
C# project structure
C# project structure

Import from C# project

Import a C# project into Eclipse:

  1. Create a blank .NET project with the project wizard and name it WebClientSample. In the .NET create-project wizard, choose Microsoft-2.0 as the Target Framework and finish the wizard.
  2. Right-click the project, choose Import and use File System, select the WebClientSample directory, then press Finish.
  3. build.xml is the default build configuration file. Listing 1 shows a default file as a created project.
Listing 1. Default build.xml file
<?xml version='1.0'?>
<project basedir='.' default='all' name='WebClientSample2'>
  <property name='nant.settings.currentframework' value='net-2.0'/>
  <property name='build' value='bin'/>
  <property name='src' value='src'/>
  <target name='all'/>
  1. We need to specify the target output file, source-code directories, resources, and the reference libraries. Listing 2 shows the example build.xml.
Listing 2. build.xml file for WebClientSample
<?xml version='1.0'?>
<project basedir='.' default='all' name='WebClientSample'>
  <property name='nant.settings.currentframework' value='net-2.0'/>
  <property name='build' value='bin'/>
  <property name='src' value='src'/>
    <target depends='WebClientSample' name='all'/>
    <target name='WebClientSample'>
    <csc debug='true' optimize='true' output='${build}/WebClientSample.exe' target='exe' 
        <include name='**/*.cs'/>
      <resources dynamicprefix="true">
        <include name='**/*.resx'/>
        <include name='${src}/Resources/*.bmp'/>
        <include name='System.dll'/>
        <include name='System.Data.dll'/>
          <include name='System.XML.dll'/>

After importing WebClientSample from the .NET SDK sample project, Figure 4 shows a C# project structure using the Package view.

Figure 4. C# project with Package view
C# project with Package view

Build, run, and debug

We need to create two external programs: Build_WebClientSample and Run_WebClientSample. Figure 5 shows Build_WebClientSample. Remember to choose your NAnt.exe path in the location. Figure 6 shows the console with the NAnt external tool.

Figure 5. Build_WebClientSample
Figure 6. Build_WebClientSample console
Build_WebClientSample console
Build_WebClientSample console

To run this sample, right-click build.xml, Run As > Open External Tools Dialog and create a Run_WebClientSample. Input the Web site URL in the arguments, such as Figure 7 shows Run_WebClientSample, and Figure 8 shows the interactive console of Run_WebClientSample.

Figure 7. Run_WebClientSample
Figure 8. Run_WebClientSample console
Run_WebClientSample console
Run_WebClientSample console


You now have a basic knowledge of Emonic and NAnt, how both can help you build .NET applications in Eclipse, and how to migrate an existing C# project into Eclipse.

Downloadable resources

Related topics

Zone=Open source
ArticleTitle=Migrate .NET applications from Visual Studio to Eclipse