Skip to main content

csharp_library

A csharp_library() rule builds a .Net library from the supplied set of C# source files and dependencies by invoking csc.

Function Signature​

def csharp_library(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str | target_name_glob] = [],
within_view: list[str | target_name_glob] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
compiler_flags: list[str] = [],
contacts: list[str] = [],
deps: list[str] = [],
dll_name: str = "",
framework_ver: str,
labels: list[str] = [],
licenses: list[str] = [],
srcs: list[str] = [],
) -> None

Parameters​

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • compiler_flags: (defaults to: [])

    The set of additional compiler flags, in which macros such as $(location //some:target) are expanded. A /target among them has no effect: the rule passes its own after them.

  • contacts: (defaults to: [])

    A list of organizational contacts for this rule. These could be individuals who you would contact in the event of a failure or other issue with the rule.

    contacts = [ 'Joe Sixpack', 'Erika Mustermann' ]
  • deps: (defaults to: [])

    The set of targets or system-provided assemblies this target depends on. Any values that are targets must be either csharp_library or prebuilt_dotnet_library instances.

  • dll_name: (defaults to: "")

    The output name of the dll. This allows you to specify the name of the dll exactly. When this is not set, the dll will be named after the short name of the target.

  • framework_ver: (required)

    The version of the .Net framework that the assembly targets. This is one of net35, net40, net45, net46.

  • labels: (defaults to: [])

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query().

  • licenses: (defaults to: [])

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query

  • srcs: (defaults to: [])

    The set of C# source files to be compiled, and assembled by this rule. Each element may be either a literal string (representing the path within this package), or a target.

Examples​

python
csharp_library(
name = 'simple',
dll_name = 'Cake.dll',
framework_ver = 'net46',
srcs = [
'Hello.cs',
],
deps=[
':other',
'mscorlib.dll',
'System.dll',
],
)

prebuilt_dotnet_library(
name = 'other',
assembly = 'other.dll',
)