Add new comment
C# Windows development for unix/linux + emacs users
I have a background developing software for both Windows and Linux, although for the last 10 years I have been mostly doing development on and for Linux. Some time ago I took an assigment
for a client involving developing Windows software. I made a first prototype using Perl on Windows which worked just fine, and the client wanted a C#/.Net version instead, so off I went.
It has been ages since I used Visual Studio, and it became clear that it was
not an environment I would be particularily effective in anytime soon. Fortnunately, most of the development tools I have been using the last years are available for Windows, so off I went to see if I could set it up on Windows.
Editing
Emacs runs j
ust fine on Windows, so that was easy. Except the current version of Emacs for Windows does not ship with syntax highlighting for C#. There are a couple of ways to get hold of these. I chose the following method:
- Get hold of a more recent cc-mode.el package t
han the one that ships with Emacs for Windows. The one that ships with it is too old for the C# package I will install next. You can get the updated cc-mode package from The cc-mode homepage. - After install
ing this, install C# for Emacs.
To get cc-mode and csharp-mode to load correctly and automatically, you probably need something like below in your emacs startup file (c:/_emacs):
(load-library " cc-mode")
(load-library "csharp-mode")
(setq auto-mode-alist (append '( ("\\\\.cs$" . csharp-mode)) auto-mode-alist))
(setq auto-mode-alist (append '( ("\\\\.build$" . sgml-mode)) auto-mode-alist))
(se tq auto-mode-alist (append '( ("\\\\.aspx$" . sgml-mode)) auto-mode-alist))
(custom-set-variables
'(global-font-lock-mode t nil (font-lock))
'(show-paren-mode t)
)
(setq-default compile-command "nant -n ologo")
(autoload 'csharp-mode "cc-mode")
Now you should be able to view and edit C# code in Emacs in full colour. Chances are you probably want a decent font, and especially if you need to code on a ultra-portable from time t
o time when even the default fonts become huge. Get and install a proper font for coding. I use Dina from DonationCoder. To have emacs use it by default, I have the following lisp code in my emacs startup fi
le (c:/_emacs):
(custom-set-faces
'(default ((t (:stipple nil :background "white" :foreground "black"
:inverse-video nil :box nil :strike-through nil
:overline nil :underline nil :slant normal
:we ight normal :height 80 :width normal
:family "Dina")))))
Compiling
.Net 2.0 ships with its own compiler named csc.exe which can be called from the command line just fine. Normally, youwould not call the compiler directl
y, but rather use Visual Studio, "make" or similar "code assembly tools". I decided to use nant for my project and it works great for my project.
Editing and fixing compiling errors in Emacs was still a bit c
umbersome. The "jump to error" code in Emacs did not work with the csc.exe compiler. Fortunately, Emacs was written with all kinds of extensibility in mind, so adding support for it was pretty easy. Stick this in your c:/_emacs file:
(setq compilation-error-regexp-alist
(append '(
;C# Compiler
("\\\\(.*\\\\[csc\\\\] \\\\)\\\\(.*\\\\)(\\\\([0-9]+\\\\),\\\\([0-9]+\\\\)): \\\\(error\\\\|warning\\\\) CS[0-9]+:" 2 3 4))compilatio n-error-regexp-alist))
(global-set-key "\\M-g" 'goto-line)(global-set-key "\\C-x\\C-k" 'compile)
Yeah, the last two lines aren't relevant for "jump to error" functionality, but they are still usef
ul.
Source Code Repository
I needed somewhere to stuff the code I write as well. Lately I've used arch (tla), but a couple of things made me move from tla to Subversion; 1) tla does not work well with W
indows, and 2) tla is a discontinued project. It's replacement (bzr/baz) doesn't work well with Windows yet. So I decided to use Subversion, which seems to run fine in both Windows and Linux. Problem solved.