OmniSharp Documentation

repository·master·Indexed 24 days ago

https://github.com/omnisharp/omnisharp-roslyn

A .NET development platform based on Roslyn workspaces that provides C# language services and project dependencies to various IDEs and plugins. It supports both Stdio and HTTP server interfaces and targets .NET 6.0 and .NET 4.7.2. The documentation covers installation, build requirements for Windows, macOS, and Linux, CLI configuration flags, and integration with VS Code.

Tokens
2.3K
Snippets
4
Records
17
Agent score
85%

What's inside OmniSharp

  1. What is OmniSharp?

    master

    OmniSharp is a .NET development platform based on Roslyn workspaces. It provides project dependencies and C# language services to various IDEs and plugins.

    Runtime Requirements

    • Windows: Built with the .NET Core SDK.
    • OSX/Linux: Built with Mono. Requires Mono version >=6.4.0 to be globally installed when using the _net472_ build.
    • Linux HTTP Interface: If you require the HTTP interface on Linux, you must have libuv installed.
    • Target Frameworks: Targets both _net6.0_ and _net472_. The _net6.0_ build requires a .NET SDK version >=6.0_.
  2. Handle One-Based vs Zero-Based indices

    master

    By default, OmniSharp uses one-based indexing (the first line and column are 1). If your editor uses zero-based indexing, you can use the --zero-based-indices flag. This allows OmniSharp to automatically translate indices to zero-based, which simplifies deserialization on the editor side.

    OmniSharp.exe --zero-based-indices
  3. Choose an OmniSharp interface (HTTP or Stdio)

    master

    OmniSharp supports two primary communication interfaces depending on your client implementation:

    1. Http (requires omnisharp.http package): A pull-based interface where the client communicates with the server over HTTP. The server cannot push information to the client. You can monitor server logs by listening to the Stdout stream. Use the -p <port> flag to specify a custom port.

    2. Stdio (requires omnisharp package): Uses standard process interfaces (Stdin for requests, Stdout for responses). This is a two-way relationship allowing the server to push information like Diagnostics, new references, or package restores. Use the -e <encoding> flag to specify the encoding for the streams.

  4. Build Requirements for OmniSharp

    master

    Before building OmniSharp, ensure your environment meets the following requirements based on your operating system:

    Windows

    macOS

    • Mono 6.6.0 or greater is required. You can install it via the official .pkg or using Homebrew:
    brew update
    brew install mono
    brew install homebrew/cask/mono-mdk

    Linux

    • Mono 6.6.0 or greater is required. Ensure you also install msbuild (which may be a separate package).
    • Note that Linux support depends on your distribution's compatibility with the .NET Core SDK. Check the official .NET dependencies list for guidance.
  5. Download OmniSharp binaries

    master

    OmniSharp is available in two flavors: Stdio server and HTTP server.

    Stable Releases

    Stable releases are published via GitHub releases. Each release contains binaries for various operating systems and architectures.

    Pre-releases and Master Builds

    Pre-release versions and automatic builds from the master branch are hosted in Azure Blob Storage. You can list available versions using the following URL pattern: https://roslynomnisharp.blob.core.windows.net/releases?restype=container&comp=list&prefix={version}

    Individual packages can be downloaded using the following convention: https://roslynomnisharp.blob.core.windows.net/releases/{version}/{packagename}-{os/arch}.{ext}

    Available Package Names:

    • omnisharp
    • omnisharp.http

    Available OS/Architecture Identifiers:

    • win-x64, win-x86, win-arm64
    • linux-x64, linux-musl-x64, linux-arm64, linux-musl-arm64, linux-bionic-arm64
    • osx
    • mono (Requires global mono installed)

    File Extensions:

    • Windows: .zip
    • Others: .tar.gz
  6. Run the OmniSharp build script

    master

    OmniSharp uses the Cake build automation system. You can trigger builds using the build.ps1 script on Windows or build.sh on macOS/Linux.

    Important Argument Syntax:

    • Windows (PowerShell): Prefix arguments with a single hyphen (e.g., -target Default).
    • macOS/Linux: Prefix arguments with a double hyphen (e.g., --target Default).
  7. Start OmniSharp with a solution file

    master

    When starting the server, you must provide a path to a specific solution file or a directory containing a solution. OmniSharp will detect the projects within and start the appropriate project systems. Note that you cannot load new projects once the server has started.

    OmniSharp.exe -s <solutionPath>
  8. Build OmniSharp from source

    master

    You can build OmniSharp manually using the provided scripts.

    On Windows:

    ./build.ps1

    On Linux / Unix:

    ./build.sh

    Build outputs are located under artifacts/publish/OmniSharp/<runtime id>/<target framework>/. The resulting executable is named OmniSharp.exe (Windows) or OmniSharp (Unix).

  9. Configure OmniSharp in VS Code

    master

    To use a specific OmniSharp binary in VS Code, update your User or Workspace settings with the omnisharp.path key.

    Supported values for omnisharp.path:

    • A direct path to the executable.
    • "latest": Consumes the latest build from the master branch.
    • A specific version string (e.g., "1.29.2-beta.60").

    To enable debugging by attaching a debugger to the OmniSharp process, set omnisharp.waitForDebugger to true. This will pause the server start and print the process ID in the OmniSharp output panel, behaving similarly to running OmniSharp with the --debug flag.

  10. Configure build settings via build.json

    master

    The build.json file allows you to define persistent build-related options. Key configuration keys include:

    • DotNetInstallScriptURL: The URL for the .NET SDK install script. Use this to pin to a specific version to avoid breaking changes.
    • DotNetChannel: The .NET Core SDK channel used for retrieving tools.
    • DotNetVersion: The .NET Core SDK version used for the build. You can pin a specific version or use the string Latest to retrieve the most recent version.