.NetCore

.NetCore language type recognition strategy

When the code main directory contains files ending with</code>and does not contain`<code>`files, the platform recognizes that the project language type is

Currently, only single-project code maintenance is supported. If you maintain multiple projects in a code repository, such as a microservice architecture, it is recommended that you separate each project into different warehouses or different secondary directories of the same warehouse.

Compilation principle

Support for the .NetCore language will build an image rather than a slug package like a Dockerfile, so .NetCore cannot be defined using a Procfile.

By default, the NetCore language build process usesmicrosoft/dotnet:2.2-sdk-alpine to compile the image andmicrosoft/dotnet:2.2-aspnetcore-runtimeto run the environment image, and the same is true if other versions are set.If you do not download the image in advance, it is easy to fail to pull the image during the build process.It is strongly recommended to manually obtain the above images on the Rainbond management node in advance.

If your source code is dependent on the system environment, you need to install the system class library separately. Currently, you cannot use the default compilation environment provided by Rainbond to compile directly. You can directly define Dockerfile to support it.

Build environment selection

The current version of the platform uses the microsoft/dotnet:2.2-sdk-alpine mirror environment for source code compilation by default.You can set the build environment version according to your needs. The optional version currently includes:

  • 3.0-sdk
  • 2.1-sdk

Set the service environment variable BUILD_DOTNET_SDK_VERSION=3.0-sdk to select the build environment version.

Compile mode settings

The default compilation method is as follows:

  1. dotnet restore
  2. dotnet publish -c Release

If the command that needs to be executed beforedotnet restorecan be specified by the BUILD_DOTNET_RESTORE_PREenvironment variable.

If you need to change the default dotnet restorecommand can be specified through theBUILD_DOTNET_RESTORE environment variable.For example, set the following environment variable:

  1. BUILD_DOTNET_RESTORE_PRE=dotnet restore --ignore-failed-sources

For the setting of environment variables, please refer to Service Environment Variables

Project run

Operating environment selection

Usually the running environment is the same as the compilation environment version. The default running environment provided by the current version ismicrosoft/dotnet:2.2-aspnetcore-runtime, and the optional running environment version is:

  • 3.0-aspnetcore-runtime

  • 2.1-aspnetcore-runtime

Set the version you need by setting the environment variableBUILD_DOTNET_RUNTIME_VERSION

The compiled result file is stored in the/appdirectory of the runtime environment.Since the platform cannot perceive the entry running file of the project well, we need to define rainbondfile in the main source directory of the source code, define the running and startup method of the project, for example:

  1. ports:
  2. - port: 5000
  3. procotol: http
  4. cmd: dotnet aspnetapp.dll

portsdefines the ports the project listens on (must listen on the pan address *or0.0.0.0)

cmdDefine the project startup method, which is based on the entry running file generated after the project is published.

How to adapt the port set in the rainbondfile

Usually, program developers do not add logic to customize program listening ports.In this case, when the program starts, it will listen to the default address http://[::]:80 So how can I make my program customize the listening port and make it dynamically match the port set in the rainbondfile? The following is a specific plan:

Modify the Program.csof the project

  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions .Configuration;
  8. using Microsoft.Extensions.Logging;
  9. namespace aspnetapp {
  10. public class Program {
  11. public static void Main (string[] args) {
  12. // Startup port
  13. defined by environment variable ${PORT} string port = "5000";
  14. if (Environment.GetEnvironmentVariable("PORT") != null) {
  15. port = Environment.GetEnvironmentVariable("PORT");
  16. }
  17. Console.WriteLine("Listing :{0}", port);
  18. CreateWebHostBuilder (port, args ).Build ().Run();
  19. }
  20. public static IWebHostBuilder CreateWebHostBuilder (string port, string[] args) =>
  21. WebHost.CreateDefaultBuilder (args)
  22. // Define access path
  23. .UseUrls ($"http:/ /0.0.0.0:{port}")
  24. .UseStartup<Startup> ();
  25. }
  26. }

sample code

https://github.com/goodrain/dotnet-demo