Migrate .NET applications from Visual Studio to Eclipse

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

Learn how to develop open source C# applications using the Emonic Eclipse plug-in and how to use Eclipse on existing Microsoft® .NET Framework V2.0 projects.

Jimmy Liao (sjliao@tw.ibm.com), Software Engineer, IBM

Jimmy Liao is a software engineer on the Mobility Collaboration Development and Test team in Taipei. Previously, he worked in the Java embedded development and testing area and has embedded-system development experience.



22 April 2008

Also available in Japanese

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.

C# and .NET in a nutshell

In 2001, Microsoft released C#, which is an object-oriented programming language and part of .NET Framework. C# uses a procedural object-oriented syntax based on C++ and draws influences from Java technology, Delphi, and Eiffel. It is intended for general-purpose use within the .NET Framework. The .NET Framework, in turn, is a collection of class libraries that developers combine with their own code, which may be C# or another language, to create Windows applications.

The Mono and DotGNU projects are open source C# compilers that implement nearly complete versions of .NET Framework libraries. Both operate on UNIX®-derived and influenced operating systems and Windows. Microsoft offers its own C# compiler and environment, called "Rotor," for non-Windows operating systems. However, licensing restrictions prevent you from deploying Rotor applications in commercial environments, which limits Rotor's usefulness.

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

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 Resources 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 http://emonic.sourceforge.net/updatesite/internap/site.xml.

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

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

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'/>
</project>
  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' 
                warninglevel='4'>
      <sources>
        <include name='**/*.cs'/>
      </sources>
      <resources dynamicprefix="true">
        <include name='**/*.resx'/>
        <include name='${src}/Resources/*.bmp'/>
      </resources>
      <references>
        <include name='System.dll'/>
        <include name='System.Data.dll'/>
          <include name='System.XML.dll'/>
        </references>
    </csc>
    </target>
</project>

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
Build_WebClientSample
Figure 6. 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 www.google.com. Figure 7 shows Run_WebClientSample, and Figure 8 shows the interactive console of Run_WebClientSample.

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

Conclusion

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.

Resources

Learn

Get products and technologies

Discuss

  • The Eclipse Platform newsgroups should be your first stop to discuss questions regarding Eclipse. (Selecting this will launch your default Usenet news reader application and open eclipse.platform.)
  • The Eclipse newsgroups has many resources for people interested in using and extending Eclipse.
  • Participate in developerWorks blogs and get involved in the developerWorks community.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Open source on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=301545
ArticleTitle=Migrate .NET applications from Visual Studio to Eclipse
publish-date=04222008