# C# Rules ## Rules

Rules

## Overview This is a minimal viable set of C# bindings for building csharp code with mono. It's still pretty rough but it works as a proof of concept that could grow into something more. If windows support ever happens for Bazel then this might become especially valuable. ## Setup Add the following to your `WORKSPACE` file to add the external repositories: ```python load("@bazel_tools//tools/build_defs/dotnet:csharp.bzl", "csharp_repositories") csharp_repositories() ``` ## Examples ### csharp_library ```python csharp_library( name = "MyLib", srcs = ["MyLib.cs"], deps = ["//my/dependency:SomeLib"], ) ``` ### csharp_binary ```python csharp_binary( name = "MyApp", main = "MyApp", # optional name of the main class. srcs = ["MyApp.cs"], deps = ["//my/dependency:MyLib"], ) ``` ### csharp\_nunit\_test ```python csharp_nunit_test( name = "MyApp", srcs = ["MyApp.cs"], deps = ["//my/dependency:MyLib"], ) ``` ## Things still missing: - Handle .resx files correctly. - .Net Modules - Conditionally building documentation. - Pulling Mono in through a mono.WORKSPACE file. ## Future nice to haves: - Building csproj and sln files for VS and MonoDevelop. - Nuget Packaging - Windows .NET framwork support ## csharp_library ```python csharp_library(name, srcs, deps, warn=4, csc) ``` Builds a C# .NET library and its corresponding documentation.
Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

warn

Int; optional; default is 4

Compiler warn level for this library. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.

## csharp_binary ```python csharp_binary(name, srcs, deps, main_class, warn=4, csc) ``` Builds a C# .NET binary.
Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

main_class

String; optional

Name of class with main() method to use as entry point.

warn

Int; optional; default is 4

Compiler warn level for this binary. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.

## csharp\_nunit\_test ```python csharp_nunit_test(name, srcs, deps, warn=4, csc) ``` Builds a C# .NET test binary that uses the [NUnit](http://www.nunit.org/) unit testing framework.
Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

warn

Int; optional; default is 4

Compiler warn level for this test. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.