Most of the Arcane API is accessible via the .Net technology. It is possible to write modules and services in C#.
The following pages are available:
In 2019, there were two environments for .Net:
.Net Core and .Net Framework share a large part of the common APIs, and there are generally no difficulties in using one or the other. The historical framework .Net Framework will no longer evolve (but will continue to be maintained), and all new features will be in the '.Net Core' framework. To simplify the nomenclature, in 2020 there will only be one name, which will be .Net.
Arcane supports both the mono and coreclr implementations. The minimum versions are 5.16 for mono and 3.0 for coreclr. For both implementations, it is possible to run C# code either with a C# main or in embedded mode with a C++ main.
The mode with the C# main allows the code to be launched like any C# code:
This mode is especially useful for debugging, for example with 'Visual Studio Code' (TODO: provide example).
The embedded mode launches the code as a C++ executable, and it is the call to Arcane::ArcaneLauncher::run() that will potentially load the '.Net' runtime and load the necessary assemblies.
.Net is a technology quite similar to java in principle. The source code can be written in several languages (C#, F#, Visual Basic). The code is compiled into a platform-independent pseudo-assembly (bytecode). The product of this compilation is called an assembly (equivalent to dynamic libraries in C++). In '.Net', the extension is .dll, just like dynamic libraries (Dynamic Loaded Library) under Windows.
Like Java, the bytecode is converted into code specific to the target machine's architecture during execution. .Net code requires the presence of a runtime to manage this part, as well as other features like the Garbage Collector.
By convention, C# files have the .cs extension. The C# code is very similar to C++ code:
.Net uses a tool called msbuild for compilation, and you must define a project in XML format containing the necessary information.
msbuild uses a project file to define the compilation elements. In principle, this project file is like the Makefile for the make tool or the CMakeLists.txt for the CMake tool. In C#, for msbuild, this file conventionally has the .csproj extension. Generally, a C# project is created in a specific directory. The dotnet new command allows you to create a directory with a project:
This will create a MyTest directory containing a Program.cs file and a MyTest.csproj file.
The MyTest.csproj file will be as follows:
and the Program.cs file as follows:
To compile this file, simply navigate to the project directory and run the dotnet build command.
The dotnet build command by default creates the assembly in the directory bin/${Config}/${framework} with Config having the value Debug or Release and framework having the value of the msbuild TargetFramework property. In our example, the directory will therefore be bin/Debug/netcoreapp3.1.
To run the program, you must run the command:
If you do not want a C# executable but want to use C# code, the functioning is almost identical, but instead of creating an executable, you must create a library. To do this, simply create the C# project with the option dotnet new classlib -n MyLib.
Adding references to Arcane DLLs is done via the <PackageReference> element in msbuild, for example:
The following nuget packages are provided by Arcane:
The page C# Extensions with Swig describes how to make Arcane classes accessible in C# and extend other classes.
First, you must have dotnet in your path. If Arcane is installed in the directory ${ARCANE_PREFIX}, then you must run the following commands:
To compile the code and install it in a directory, you must execute the following command:
This will result in the generated files being installed in the out directory. If the project is named 'toto', you will have the following files: