Skip to content

Latest commit

 

History

History
508 lines (420 loc) · 30.3 KB

core.rst

File metadata and controls

508 lines (420 loc) · 30.3 KB

Core dotnet rules

These are the core dotnet rules, required for basic operation. The intent is that theses rules are sufficient to match the capabilities of the normal dotnet tools.


This builds a dotnet assembly from a set of source files. The rule generates assebly respectively for Mono, .NET Core and .NET.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule. It must have .dll extension.
deps label_list None
The direct dependencies of this library. These may be dotnet_library rules or compatible rules with the DotnetLibrary provider.
resources label_list None
The list of resources to compile with. Usually provided via reference to dotnet_resx or the rules compatible with DotnetResource provider
srcs label_list None
The list of .cs source files that are compiled to create the assembly. Only .cs files are permitted
out string ""
An alternative name of the output file
defines string_list None
The list of defines passed via /define compiler option
unsafe bool False
If true passes /unsafe flag to the compiler
keyfile label None
The key to sign the assembly with.
data label_list None
The list of additional files to include in the list of runfiles for compile assembly

Example

dotnet_library(
    name = "foo_bar.dll",
    srcs = [
        "foo.cs",
        "bar.cs",
    ],
    deps = [
        "//examples/example_lib:MyClass",
        "@npgsql//:npgsqllib",
    ],
    visibility = ["//visibility:public"],
)

[core_library(
  name = "{}_TransitiveClass-core.dll".format(framework),
  srcs = [
      "TransitiveClass.cs",
  ],
  dotnet_context_data = "@io_bazel_rules_dotnet//:core_context_data_{}".format(framework),
  visibility = ["//visibility:public"],
  deps = [
      "@io_bazel_rules_dotnet//dotnet/stdlib.core/{}:system.private.corelib.dll".format(framework),
      "@io_bazel_rules_dotnet//dotnet/stdlib.core/{}:system.runtime.dll".format(framework),
  ],
) for framework in DOTNET_CORE_FRAMEWORKS]

This builds an executable from a set of source files (respectively for Mono, .NET and .NET Core). You can run the binary with bazel run, or you can build it with bazel build and run it directly.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule. It must have .exe extension.
deps label_list None
The direct dependencies of this library. These may be dotnet_library rules or compatible rules with the DotnetLibrary provider.
resources label_list None
The list of resources to compile with. Usually provided via reference to dotnet_resx or the rules compatible with DotnetResource provider
srcs label_list None
The list of .cs source files that are compiled to create the assembly. Only .cs files are permitted
out string ""
An alternative name of the output file
defines string_list None
The list of defines passed via /define compiler option
unsafe bool False
If true passes /unsafe flag to the compiler
keyfile label None
The key to sign the assembly with.
data label_list None
The list of additional files to be included as runfiles for the generated executable

Example

dotnet_binary(
    name = "foo_bar.exe",
    srcs = [
        "foo.cs",
        "bar.cs",
    ],
    deps = [
        "//examples/example_lib:MyClass",
        "@npgsql//:npgsqllib",
    ],
    visibility = ["//visibility:public"],
)

This builds a set of tests that can be run with bazel test. '_nunit_' rules use NUnit2, '_nunit3_' rules use NUnit3, '_xunit_' rules use xunit.

To run all tests in the workspace, and print output on failure, run

bazel test --test_output=errors //...

You can run specific tests by passing the --test_filter=pattern argument to Bazel. You can pass arguments to tests by passing --test_arg=arg arguments to Bazel.

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule. It must have .dll extension.
deps label_list None
The direct dependencies of this library. These may be dotnet_library rules or compatible rules with the DotnetLibrary provider.
resources label_list None
The list of resources to compile with. Usually provided via reference to dotnet_resx or the rules compatible with DotnetResource provider
srcs label_list None
The list of .cs source files that are compiled to create the assembly. Only .cs files are permitted
out string ""
An alternative name of the output file
defines string_list None
The list of defines passed via /define compiler option
testlauncher Label <as required by unit framework>
The list of defines passed via /define compiler option

Test example

dotnet_nunit_test(
    name = "MyTest.dll",
    srcs = [
        "MyTest.cs",
    ],
    deps = [
        "//examples/example_lib:MyClass",
        "@nunitv2//:netstandard1.0_net",
    ],
)

This builds a dotnet .resources file from a single .resx file.

.NET Core version uses a custom tool to convert text .resx file to .resources files because no standard tool is provided.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule.
src label mandatory value
The .resx source file that is transformed into .resources file. Only .resx files are permitted
identifer string ""
The logical name for the resource; the name that is used to load the resource. The default is the basename of the file name (no subfolder).
out string ""
An alternative name of the output file
simpleresgen Label <as required>
An alternative tool for generating resources file. It is used by .NET Core to use a custom //tools/simpleresgen tool

Example

dotnet_resx(
    name = "Transform",
    src = ":src/ClientUtilities/util/Transform.resx",
)

This builds a dotnet .resources files from multiple .resx file (one for each).

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule.
srcs label_list mandatory value
The source files to be embeded.
identiferBase string ""
The logical name for given resource is constructred from identiferBase + "." + "directory.repalce('/','.')" + "." + basename + ".resources". The resulting name that is used to load the resource.
fixedIdentifierBase string ""
The logical name for given resource is constructred from fixedIdentiferBase + "." + "." + basename + ".resources. The resulting name that is used to load the resource. Either identifierBase of fixedIdentifierBase must be specified
simpleresgen Label <as required>
An alternative tool for generating resources file. It is used by .NET Core to use a custom //tools/simpleresgen tool

This wraps a resource so it can be embeded into an assembly.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule.
src label mandatory value
The source to be embeded.
identifer string ""
The logical name for the resource; the name that is used to load the resource. The default is the basename of the file name (no subfolder).

This wraps multiple resource files so they can be embeded into an assembly.

Providers

Attributes

This imports an external dll and transforms it into DotnetLibrary so it can be referenced as dependency by other rules. Often used with dotnet_nuget_new.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule.
deps label_list None
The direct dependencies of this dll. These may be dotnet_library rules or compatible rules with the DotnetLibrary provider.
src label mandatory value
The file to be transformed into DotnetLibrary provider

Example

See dotnet_nuget_new.

This imports a frameworkl dll and transforms it into DotnetLibrary so it can be referenced as dependency by other rules. Uses by //dotnet/stdlib... packages.

Providers

Attributes

Name Type Default value
name string mandatory value
A unique name for this rule.
deps label_list None
The direct dependencies of this dll. These may be dotnet_library rules or compatible rules with the DotnetLibrary provider.
data label_list None
The list of additional files to include in the list of runfiles for compile assembly
dll label ""
The file to be transformed into DotnetLibrary provider. If empty then name is used.