Wed 7 Nov 2007
C# with SlickEdit : No Visual Studio Required
Posted by Matthew E under Programming, SlickEdit Products
[6] Comments
“No Visual Studio® Required”
SlickEdit C# Project Tutorial
In this tutorial, we’ll build a simple C# console application with SlickEdit. This tutorial assumes you have the .NET Framework 2.0 and the C# compiler (Csc.exe) installed under %WINDIR%\Microsoft.NET\Framework\v2.0.50727. The Windows SDK (v6.0 or later) or the full .NET Framework SDK is required for the mdbg.exe managed code debugger.
Conventions
Dark blue italics represent menu commands: File > New
Bold items represent names of dialog buttons, labels, and controls: Location:
Monospaced fonts are used for environment variables, file paths and names, and text that you type into dialog controls:
Several screenshot
links are provided that show how the dialogs are used.
Creating the starter project
- In SlickEdit, go to Project > New. Create a (generic) project.
You probably want to use the Create project directory from project name option. Change the Location: to a directory where you want the project to go. Click OK to create the starter project. Dismiss the project properties dialog if it appears afterwards. - Go to File > New Item from template…
Under Installed Templates \ CSharp, highlight the C# Main Entry Point template. Change the Name in the lower portion of the dialog, and check the “Add to current project” checkbox. Click Add, and the new file will be created. It should appear under the Source Files project folder. Edit the Main() method. Add the following code inside the Main()
[cc lang="csharp"]
#if DEBUG
Console.WriteLine(“Hello World – Debug”);
#else
Console.WriteLine(“Hello World – Release”);
#endif
[/cc] - Go to Project > Workspace Properties to display the workspace properties dialog. A SlickEdit Workspace (.vpw) is the equivalent of a Solution (.sln) in Visual Studio. Click the Environment button to display the Workspace Environment Options dialog.
- Click Set Environment Variable . Create a new variable named DOTNETDIR , and point it to your .NET framework that you want to use for the C# compiler, like C:\Windows\Microsoft.NET\Framework\v2.0.50727.
To use an existing environment variable in the definition of the workspace environment use the %(VARIABLE) syntax, and not the %VARIABLE% syntax. For example: %(WINDIR)\Microsoft.NET\Framework\v2.0.50727
Be sure to select environment variable names that do not already exist. - Create another variable named WINSDKDIR , and point it to the Windows SDK or .NET Framework SDK, like C:\Program Files\Microsoft SDKs\Windows\v6.0 . You want this to be a directory where the mdbg.exe managed code debugger can be found.
- Click OK. You will be prompted that you need to close and reopen the workspace for the variables to be set.
Setting up the build command
- Once you’ve closed and reopened the workspace, go to Project > Properties to show the dialog. In the Settings for: combo, select Release, which should be the only other choice right now.
- Go to the Tools tab and remove the Compile and Rebuild tools. (Use the red X button) This should leave Build, Debug, and Execute.
- Highlight the Build tool.
Change the Command line: entry field to the following:
[cc]%(DOTNETDIR)\csc.exe /warn:3 /target:exe /define:TRACE /debug- /out:%bdSeHello.exe %{*.cs}[/cc]
The %bd in the above command line is a variable that represents the build output directory, in this case Release\.
The %{*.cs} construct means all project files that end with the .cs extension - Replace SeHello.exe with whatever you want the exe to be named. You shouldn’t need to change the Run from dir: entry field as it should already be %rw
- Make sure the Capture Output and Output to build window options are selected.
- Highlight the Execute tool.
Change the command line to “SeHello.exe”, or whatever your exe output name is from the Build tool command line. Change the Run from dir: option to %bd - Make sure the Capture Output and Output to build window options are selected.
- Click OK to close the dialog and save the changes. You should now be able to execute a build from Build > Build , and see the output of the C# compiler. If the build succeeds, Project > Execute should run the console program and display the “Hello World-Release” results.
Setting up the debug build
- Open the project properties dialog again, and click Configurations . Click New to create the Debug configuration, and copy the settings for the Release configuration.
- Click OK to create the Debug config, and dismiss the dialogs.
- Back on the project properties dialog, highlight the Tools tab, and select Debug from the Settings for: combo box.
- Highlight the Build tool name
, and change the Command line: entry field to:
[cc]%(DOTNETDIR)\csc.exe /warn:3 /target:exe /define:DEBUG;TRACE /debug+ /out:%bdSeHello.exe %{*.cs}[/cc]
All we did was add the DEBUG define and change /debug- to /debug+. Again, use your exe name in place of SeHello.exe if you want. - Highlight the Execute tool name, and make sure it is the same as you set up for the Release configuration.
- Click OK to save and close the project properties.
- Go to Build > Set Active Configuration … and select Debug.
- Execute the Build > Build command. If the build suceeds, run the Build > Execute command. You should see the “Hello World – Debug” output in the build window.
Setting up the console debugger
- Back on the project properties dialog, highlight the Tools tab, and select Debug from the Settings for: combo box.
- Highlight the Debug tool name,
and change the Command line: entry field to:
[cc]%(WINSDKDIR)\Bin\mdbg.exe SeHello.exe[/cc]
Again, change SeHello.exe to your exe name as needed. Run from dir: should be set to %bd - Make sure the Capture Output and Output to build window options are selected.
- Click OK to save and close the project properties.
- Run the Build > Debug command. The build window should have focus with a blinking cursor just after the first mdbg> prompt.
- Enter the following commands in order, pressing <enter> after each one.
- print args to show the value of the args variable.
- next to do a step over
- go to continue execution
- quit to quit the debugger (IMPORTANT!)
- The entire debug session output should look like the following.
C:\Dev\Lab\TestProjects\SeHello\Debug
> C:\WinSDK\Bin\mdbg.exe SeHello.exe
MDbg (Managed debugger) v2.0.50727.312 (rtmLHS.050727-3100) started.
Copyright (C) Microsoft Corporation. All rights reserved.
For information about commands type “help”;
to exit program type “quit”.
run SeHello.exe
STOP: Breakpoint Hit
16: static void Main(string[] args) {
[p#:0, t#:0] mdbg> print args
args=array [0]
[p#:0, t#:0] mdbg> next
19: Console.WriteLine(“Hello World – Debug”);
[p#:0, t#:0] mdbg> go
Hello World – Debug
STOP: Process Exited
mdbg> quit
C:\Dev\Lab\TestProjects\SeHello\Debug
>
Handling complex build commands
A small console application like this one doesn’t have any extensive dependencies, and most of the default options for the C# compiler are fine. However, more complex projects will require many more options to be passed on the command line. For these cases, it can be useful to create an options file for all of the command line switches.
- Go to File > New to create a new text file and add it to the project.
For this example, we’ll create the command line options for the debug build in a file called Debug.opts - Edit the new options file and put in the following contents, which should match your first few options on the Debug build command line:
[cc]/warn:3 /target:exe /define:DEBUG;TRACE /debug+[/cc] - Open the Project Properties dialog to the Tools tab, select the Debug configuration, and highlight the Build tool.
Change the build command to:
[cc]%(DOTNETDIR)\csc.exe @Debug.opts /out:%bdSeHello.exe %{*.cs}[/cc] - You can now run the Build > Build command to make sure the options file was correctly read.
November 7th, 2007 at 2:00 pm
While it works okay for C# there are still many little quirks, which I have reported to the slickedit team. Also no out of the box support for Mono for C# development on Linux, Solaris, Windows and more.
April 3rd, 2009 at 2:45 am
Hi,
I want to know what will be the code to “stop” or “close” or “end” .exe process with a button in C# language ?
while I start my .exe file with command
”
Process.Start(@”C:\windows\notepad.exe”);
”
now i want to close this process with simple GUI Button in C#
can any body tell me what will be the code?
December 14th, 2009 at 11:45 am
Hello, wanderful page. Thank you.
January 28th, 2010 at 2:28 pm
DAHA IYI
February 10th, 2010 at 7:17 pm
Hello, beautiful web site. Thank you.
December 28th, 2012 at 4:53 am
hi,
how to create a batch file, send a sample