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 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
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.
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
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
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.
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.
Figure 3 shows a C# project structure in explorer view.
Figure 3. C# project structure
Import a C# project into Eclipse:
- 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.
- Right-click the project, choose Import and use File System, select the WebClientSample directory, then press Finish.
- 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>
|
- 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
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
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
Figure 8. 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.
Learn
-
Read about another C# plug-in for Eclipse dubbed the Improve C# Plug-in for Eclipse.
-
Read the developerWorks article "Developing
applications using the Eclipse C/C++ Development Toolkit" to learn how to create a C++
application using the Standard Template Library and the CDT.
-
Check out the "Recommended Eclipse reading list."
-
Browse all the Eclipse content on developerWorks.
-
New to Eclipse? Read the developerWorks article "Get started with Eclipse Platform" to learn its origin and architecture, and how to extend Eclipse with plug-ins.
-
Expand your Eclipse skills by checking out IBM developerWorks' Eclipse project resources.
-
To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.
-
Stay current with developerWorks' Technical events and webcasts.
-
Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
-
Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
-
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
Get products and technologies
-
Download the .NET
Framework 2.0 Software Development Kit (SDK) (x86) from the .NET Framework
Downloads section of the MSDN .NET Framework site.
-
Download the latest version of the Emonic
plug-in, an Eclipse plug-in that allows you to build C# programs with Mono or Microsoft .NET.
-
Download the latest version of NAnt a free .NET build tool.
-
Check out the latest Eclipse technology downloads at IBM alphaWorks.
-
Download Eclipse Platform and other projects from the Eclipse Foundation.
-
Download IBM product evaluation versions, and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
-
Innovate your next open source development project with IBM trial software, available for download or on DVD.
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.



