Demo C# App Now we have setup the .NET development environment for Eclipse. Let's test it with a small demo application. Create a new .NET project through File > New > .NET Project. On the New .NET Project window, name the project as 'DemoProject' and select the Target Framework as Microsoft-2.0. When you click on 'Finish', a C# project structure gets created.
Now we will add a C# source class file which will display a message in the console. For this, right-click on the src folder under the DemoProject in the Navigator pane, and select New > C# Class. Give the name and the target name as Demo and click on 'Finish'. Add the following code snippet to the Demo class which upon build will display a message on console:
class Demo{ static void Main() { System.Console.WriteLine("Testing Emonic for Eclipse !!!!"); }}
Building and running the Project The build.xml file which is created with the project automatically is configured with the target output file, source-code directories and other dependencies. As we are using NAnt, we need to create two external programs, one to build and other to run the demoProject. To create a build program, right-click on build.xml, and select Run As > Open External Tools Dialog. Now in the External Tools window, select Program on left pane and press 'New' icon to launch a new configuration wizard.
Give name of the program as Build_DemoProject and under the Main tab, provide the Location of the NAnt.exe and provide the Working Directory to DemoProject directory by clicking the Browse workspace button. Now click on 'Run' to build the project. Once the project is built successfully, expand the bin node of DemoProject directory and you'll see that a demo.exe file has been created as an output.
Now to execute that, we need to create another external program. Name the new External tools programs as Run_DemoProject, and in the Location option, provide the path of the Demo.exe through Browse Workspace button and keep the target for the Working Directory as DemoProject only. Upon clicking the Run button, the message will appear on the console of the Eclipse IDE.
Migrating .NET project from Visual Studio to Eclipse As we have set the .NET Framework development environment for Eclipse, we can migrate existing .NET projects from Visual Studio to Eclipse and work on them. Not only we can change the code of the application's project but also build and execute the project as well. Here we demonstrate a migration of an existing C# project from Visual Studio to Eclipse, and then we will build the same in Eclipse and execute it.
For the demonstration, we will use a Temperature Converter application build in C#, which takes the input as Fahrenheit and displays the result in equivalent Celsius.
Importing the project The project which we are importing from Visual studio is named as TempConv. Create a new .NET project in Eclipse and name it as TempConv. Now right-click on project directory and select 'Import' , and in the following list select 'File System' and click on 'Next' . In the following Import window, pass the location of the TempConv project in the Visual Studio's workspace and select the files or folders that you wish to move to the Eclipse environment. After the import is done, open the build.xml file and specify the target as well as the output directories. The following code snippet shows that:
Now we can build and execute the application by creating external program following the same steps as we did for the demo application earlier. When we run the project we can can see the output in a form dialog window appearing which prompts for input in form of Fahrenheits and when OK button is clicked, corresponding Celsius result is displayed. The .NET Framework has successfully been set up for development of C# application on Eclipse platform using Emonic and NAnt.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.