C# Compiling

Compiling a basic C# application is as simple as passing the desired filename and a list of source files to the CSharp generator (assuming a C# compiler is in your path).

    import 'csharp'
    gen CSharp, "example.dll", :sources => sys["**/*.cs"]

This creates a file task called "example.dll". Source files can be specified as a FileList, array, or string. The created task is dependent on all source files, so if any of them change the dll will be recompiled. You can specify library and resource files in the same manner

    gen CSharp, "example.dll", :sources => sys["**/*.cs"],
                               :libs    => ["mylib.dll", "mylib2.dll"]
                               :res     => "myres.resource"

The generator guesses what type of output you want by inspecting the file extension of the out file ("example.dll"). exe will be compiled to winexe, netmodule to module, and all others to dll. You can override this by providing a :target key in the parameter hash. Any other parameters you specify are passed through to the C# compiler.

    gen CSharp, "example.exe", :sources     => sys["**/*.cs"],
                               :target      => "exe",
                               :warnaserror => true

Alternate Compilers

The CSharp generator searches your path for one of 3 known C# compilers - csc, mcs, and gmcs. You can specify a different compiler by providing a compiler adapter through the :compiler key. The existing compiler adapters provide a one parameter constructor that allows you to specify the path to that compiler. Or you can of course provide your own implementation.

    csc11 = CscCompiler.new("/path/to/csc1.1")
    gen CSharp, "example.dll", :sources  => sys["**/*.cs"],
                               :compiler => csc11

Resource Generation

A generator is provided to create a rule for compiling resource files with resgen. This is quite powerful as it allows you to simply reference the compiled resource files in you CSharp generator, and they will automatically be built as required.

    import "resgen"
    gen Resgen, :build_dir => "build/", :namespace => "Example"

    # properties/resource.resx => build/Example.Properties.Resource.resources
    # MyRes.resx               => build/Example.MyRes.resources

Running NUnit

You can easily run an NUnit test suite using the NUnitTest generator

    import "nunittest"
    gen NUnitTest, "test", :dlls => ["mytest1.dll", "mytest2.dll"]

By default, nunit-console is used, and it must exist in your path. You can specify a different test runner using the :bin key. Any other arguments are passed through to the test runner

    gen NUnitTest, "test", :dlls => sys["test/*.dll"],
                           :bin  => "my-test-runner",
                           :xml  => "results.xml"