Eiffel .NETCore execution

This document provide a quick overview on how to execute Eiffel.NetCore applications. It covers various aspects including the wrapper project, execution, publishing, debugging in VisualStudio, and known limitations

At the moment, the EiffelStudio debugger has no support Eiffel .NET Core. It is, however, possible to execute most of the Eiffel .NET Core application from the IDE using the Run command. The execution will be outside EiffelStudio.

The generated executable can not be executed by itself and requires to be launched using the dotnet tool from the command line.

Note: Use the command: dotnet <app_name> or dotnet run <app_name>.

Wrapper project

To help the user, the EiffelStudio compiler also generates a C# wrapper project (located in W_code or F_code directories). See the wrapper_*.cs and wrapper_*.csproj files. This simple C# wrapper project is simply a way to include and instantiate the Eiffel .NETCore code.

This "wrapper" project is useful for:

  • using profile
  • publishing the executable
  • debugging using VisualStudio.
  • Working with any specific tool that requires a C# project

See the next sections for more information.

For an application named "app_netcore":

  • the C# code is quite simple:

... public class wrap_app_netcore { public static void Main() { MAIN.Main(); } }Note: the MAIN.Main() is the main entry point of the Eiffel .NETCore application.

  • the wrap_app_netcore.csproj file looks like:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>disable</Nullable> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> None </ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> </PropertyGroup> <ItemGroup> <Reference Include="app_netcore"> <HintPath>app_netcore.exe</HintPath> </Reference> <Reference Include="EiffelSoftware.Runtime"> <HintPath>Eiffelsoftware.Runtime.dll</HintPath> </Reference> </ItemGroup> </Project>

Execution

It is possible that an application requires additional setting (for example web APIs application), in this case the dotnet run tool can use a specific profile using the syntax --launch-profile <NAME>.

Read more about the dotnet tool, and especially the run command at https://learn.microsoft.com/fr-fr/dotnet/core/tools/dotnet-run .

Publishing

The wrapper project is helpful to publish the executable to the current or other platforms, and have an executable that does not require the dotnet command. It is also possible to include all dependencies (i.e: self contained) to ease deployment on machine without any dotnet runtime installed.

Note: use the dotnet publish tool on the generated wrapper project. See the documentation about dotnet publish at https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish .

Debugging in VisualStudio

Even if EiffelStudio does not provide any support for debugging Eiffel .NETCore directly from the IDE.

It is possible to use, for instance, VisualStudio to debug the generated Eiffel .NETcore application thanks to the wrapper C# project.

A solution is to use the C# wrapper project generated by the Eiffel compiler (in W_code or F_code directory) within VisualStudio.

  • Open the C# .csproj file with VisualStudio (it includes the associated Eiffel output dll or exe)
  • Configure the Debugging profile
  • Launch the execution with VisualStudio, and debug.

Limitations

In the current version, the EiffelStudio compiler will always generate a Microsoft.NET.Sdk C# wrapper project. But this is not always the expected type SDKs.

For instance when using ASP.NETCore, it is expected to use Microsoft.NET.Sdk.Web.

In such case, the generated .csproj file needs to be manually modified to set the expected SDK, and also the various package dependencies.

For instance:

  • replace the first line of the .csproj file by <Project Sdk="Microsoft.NET.Sdk.Web">
  • and in the <ItemGroup> section, list the package references such as <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.10" />

This allows the application to be run and, if necessary, debugged using VisualStudio.

Info: To learn more, check the Eiffel .NETCore examples at Eiffel .NET samples.