Troll coworkers - use Emacs at work for csharp!
Clone or download
razzmatazz Merge pull request #454 from M-frankied/ido-use-ido
auto-complete-display-backend 'ido' should use ido
Latest commit 260b242 Oct 22, 2018
Failed to load latest commit information.
doc omnisharp-solution-errors: add documentation to doc/ Dec 26, 2017
features-tbd-on-the-server-side Fix tbd integration tests running anyway Jul 4, 2015
ignored-from-melpa-build Add a way to start developing nicely May 3, 2016
test-stuff .travis.yml: remove dependency on mono Sep 24, 2017
test omnisharp-solution-errors: emit proper error/warning code Aug 5, 2018
.gitignore Ignore compiled lisp files Jun 19, 2018
.travis.yml Probably building image every time is faster than uploading/downloadi… Jul 22, 2017
Cask omnisharp.el: fix compilation errors w/emacs 24 Nov 15, 2017
Dockerfile.testing use omnisharp--install-server for unit testing too Nov 19, 2017
LICENSE add LICENSE and insert GPLv3 license headers to most of the files Aug 3, 2017 fix typo minibufer -> minibuffer Aug 19, 2018
docker-compose.yml speed things up with unit testing with docker Dec 26, 2017
omnisharp-auto-complete-actions.el support yas snippet completions in 'ido' backend too Oct 21, 2018
omnisharp-current-symbol-actions.el Remove broken interactive rename Oct 21, 2018
omnisharp-format-actions.el Add ability to run fix usings Oct 18, 2018
omnisharp-helm-integration.el omnisharp-helm-find-symbols: tune the helm candidate output slightly Aug 14, 2017
omnisharp-http-utils.el add LICENSE and insert GPLv3 license headers to most of the files Aug 3, 2017
omnisharp-navigation-actions.el Remove broken interactive rename Oct 21, 2018
omnisharp-server-actions.el omnisharp-start-omnisharp-server: remove dependency on helm Oct 15, 2017
omnisharp-server-installation.el use omnisharp--install-server for unit testing too Nov 19, 2017
omnisharp-server-management.el omnisharp-test-actions: update a bit on top of work of @alistair Oct 14, 2018
omnisharp-settings.el make completing read customizable, DWIM by default Oct 21, 2018
omnisharp-solution-actions.el New project solutions don't require adding files to solution Oct 21, 2018
omnisharp-unit-test-actions.el omnisharp-test-actions: update a bit on top of work of @alistair Oct 14, 2018
omnisharp-utils.el make completing read customizable, DWIM by default Oct 21, 2018
omnisharp.el Remove broken interactive rename (II) Oct 22, 2018 speed things up with unit testing with docker Dec 26, 2017 Add helper script for starting emacs in the project environment Oct 18, 2014


omnisharp-emacs is a port of the awesome omnisharp-roslyn server to the Emacs text editor. It provides IDE-like features for editing files in C# solutions in Emacs, provided by an OmniSharp server instance that works in the background.

Note that C# syntax highlighting and indenting is provided by csharp-mode which is a dependency of this package. See Configuration section below on how to enable omnisharp-mode via the csharp-mode hook.

This package is licensed under GNU General Public License version 3, or (at your option) any later version.


Please see omnisharp-emacs Features. Please note that information on the Features page is outdated and some commands are not ported to the new roslyn version of omnisharp-emacs yet.

Package Installation

This package requires Emacs 24.4 and above. It has been tested on Ubuntu, Windows 7+ and on macOS.

External Dependencies

You may need to have one or more of .NET SDKs (and mono – on UNIX platforms) installed for your project to be properly processed by omnisharp server.

Note that multiple .NET SDKs can be installed in parallel, too.


Installation on Spacemacs

Add csharp layer to dotspacemacs-configuration-layers on your .spacemacs file and restart Emacs or run dotspacemacs/sync-configuration-layers (SPC f e R in evil mode, M-m f e R in Emacs mode). csharp-mode and omnisharp packages will get installed automatically for you as the configuration is reloaded.

Installation on Regular Emacs

To install, use MELPA. After MELPA is configured correctly, use

M-x package-refresh-contents RET
M-x package-install RET omnisharp RET

to install.

When installing the omnisharp package package.el will also automatically pull in csharp-mode for you as well.

You can also add

(package-install 'omnisharp)

to your init.el to force installation of omnisharp-emacs on every install.


This section describes an example configuration for omnisharp-emacs. This is not required if you are using spacemacs unless you want to override existing bindings, etc.

Applying omnisharp-mode and auto-starting server when visiting C# files

Add this to csharp-mode-hook to your init.el to automatically invoke omnisharp-emacs when opening C# files:

(add-hook 'csharp-mode-hook 'omnisharp-mode)

omnisharp-emacs will attempt to start a server automatically for you when opening a .cs file (if a server has not been started already). Otherwise, you will need to start the server with M-x omnisharp-start-omnisharp-server RET should it fail to find a .sln file or project root (via projectile). It will prompt you for a solution file or project root directory you want to work with.


For autocompletion via company mode to work you will also need this in your init.el:

 '(add-to-list 'company-backends 'company-omnisharp))

(add-hook 'csharp-mode-hook #'company-mode)


omnisharp-emacs supports Flycheck and it can be enabled automatically by hooking up flycheck-mode to be enabled for csharp-mode buffers:

(add-hook 'csharp-mode-hook #'flycheck-mode)

Combined setup example

This is an example code that will enable company-mode and flycheck-mode and will set some formatting variables for csharp-mode. Also, it shows how to setup keybindings for csharp-mode.

  '(add-to-list 'company-backends #'company-omnisharp))

(defun my-csharp-mode-setup ()

  (setq indent-tabs-mode nil)
  (setq c-syntactic-indentation t)
  (c-set-style "ellemtel")
  (setq c-basic-offset 4)
  (setq truncate-lines t)
  (setq tab-width 4)
  (setq evil-shift-width 4)

  ;csharp-mode recommends this too
  ;(electric-pair-mode 1)       ;; Emacs 24
  ;(electric-pair-local-mode 1) ;; Emacs 25

  (local-set-key (kbd "C-c r r") 'omnisharp-run-code-action-refactoring)
  (local-set-key (kbd "C-c C-c") 'recompile))

(add-hook 'csharp-mode-hook 'my-csharp-mode-setup t)

There is also an example configuration for evil-mode included in the project, please see doc/example-config-for-evil-mode.el.

Server Installation

This emacs package requires the omnisharp-roslyn server program. Emacs will manage connection to the server as a subprocess.

The easiest/default way to install the server is to invoke M-x omnisharp-install-server and follow instructions on minibuffer.

If that fails (or you feel adventurous) please see installing omnisharp server on how to install the server manually.


Most of the time (if the server has been installed properly) you can diagnose issues by looking at the *omnisharp-log* buffer where omnisharp-emacs emits any log messages from the omnisharp server.

macOS: Mono.framework not on $PATH

Some projects may fail to load in omnisharp-server when Mono.framework is not on $PATH or $PATH is not picked up by emacs.

An example output in omnisharp-log is:

[12:23:33] ERROR: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo, The reference assemblies for
framework ".NETFramework,Version=v3.5" were not found. To resolve this, install the SDK or
Targeting Pack for this framework version or retarget your application to a version of the framework
for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from
the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your
assembly may not be correctly targeted for the framework you intend.

See issue #426.

Missing .NET SDKs

You may find that your project can not be loaded when .NET SDK is not installed on your machine.

A log line indicating the problem would look like this on *omnisharp-log*:

[19:24:59] WARNING: Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. ...

Error loading csproj file

You may encounter an issue where omnisharp server fails to load a project, this looks like on *omnisharp-log*:

[22:46:22] WARNING: OmniSharp.MSBuild.MSBuildProjectSystem, Failed to load project file '/Users/{user}/temp/temp.csproj'.

To fix this, on Linux, you may need to install the msbuild-stable package.

This issue and a fix has been reported on issue #430.


How to run tests

You can run all kind of tests by following shell script.


Pull requests welcome!