XSharp builds on .Net Core
Posted: Wed Jul 29, 2020 2:29 pm
I would like to share some progress that I made today.
I have changed the X# build system to support building for .Net Core. Consider an app that has one PRG file and a XSPROJ file.
The contents of the XSProj file looks like this:
As you can see we are compiling for .Net Core 5.0 and for the VO dialect. I have included the XSharp assemblies needed to open a DBF file. The only "strange" thing in here is the package references to the System.Text.Encoding.CodePages package, because by default .Net Core does not have support for Codepage 1252 which I am using.
Unlike traditional project files there are no items included. By default .Net Core includes all source code items in the folder.
The code looks like this:
As you can see I am calling a function in the Encoding class to link the package that has the codepage support.
The rest is a normal mixture of Xbase code and .Net code.
To compile and run the program I type on the command line.
The result is this:
As you can see the runtime, RDD system and Macro compiler all work on .Net Core 5.0 !
You can deploy this app with all support DLLs in one single Exe and 2 small DLLs by calling:
This creates the following files, which make up the whole program:
Even the XSharp DLLs are included in test,exe. The total size is 29 Mb.
You can also prepare an image for Linux by replacing win-x64 with linux-x64 and then the output is:
A self contained .Net app for Linux in 44 Mb !
I hope you find this interesting.
Robert
And yes this will be included in the next build. Not with the VS project system, that will take a bit longer.
I have changed the X# build system to support building for .Net Core. Consider an app that has one PRG file and a XSPROJ file.
The contents of the XSProj file looks like this:
Code: Select all
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(XSharpMsBuildDir)XSharp.NET.Sdk.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5.0</TargetFramework>
<ins>true</ins>
<dialect>vo</dialect>
</PropertyGroup>
<ItemGroup>
<Reference Include="XSharp.Core" />
<Reference Include="XSharp.RT" />
<Reference Include="XSharp.RDD" />
<Reference Include="XSharp.MacroCompiler" />
</ItemGroup>
<Import Project="$(XSharpMsBuildDir)XSharp.NET.Sdk.targets" />
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
</ItemGroup>
</Project>
Unlike traditional project files there are no items included. By default .Net Core includes all source code items in the folder.
The code looks like this:
Code: Select all
USING System.Text
FUNCTION Start() AS VOID
FIELD CUSTNUM, LASTNAME, FIRSTNAME
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
? "Hello from X#"
? "OS :",OS(TRUE)
? "Framework:", System.Environment.Version:ToString()
? "Xsharp : version", Version(), "dialect", RuntimeState.Dialect:ToString()
? "Datetime :", DateTime()
? "Program :", ExecName(TRUE)
? "Workdir :", WorkDir()
? "Curdir :", System.IO.Directory.GetCurrentDirectory()
? "Opening, Indexing and listing a DBF with .Net Core"
?
USE Customer
INDEX ON LASTNAME TO LASTNAME
DO WHILE ! EOF()
? Str(CUSTNUM,2) , LASTNAME, FIRSTNAME
SKIP
ENDDO
? "Press any key"
Console.ReadLine()
RETURN
The rest is a normal mixture of Xbase code and .Net code.
To compile and run the program I type
Code: Select all
dotnet run
The result is this:
Code: Select all
Hello from X#
OS : Windows 10 Enterprise (x64) ( Version 10.0, Build 18363 )
Framework: 5.0.0
Xsharp : version XSharp 2.5.2.0 dialect VO
Datetime : 29-07-2020 16:10:58
Program : C:testbinDebugnetcoreapp5.0test.dll
Workdir : C:testbinDebugnetcoreapp5.0
Curdir : C:test
Opening, Indexing and listing a DBF with .Net Core
6 Baker James
2 Borne Maria
15 Chandler Walter
3 Cooper Elizabeth
12 Cusumano Karen
5 Dougherty Janet
.
.
14 Walsh Gloria
19 Zimmerman Carla
Press any key
You can deploy this app with all support DLLs in one single Exe and 2 small DLLs by calling:
Code: Select all
dotnet publish --self-contained true -r win-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true
Code: Select all
29-07-2020 16:13 28.955.153 test.exe
28-05-2020 08:26 500.608 hostfxr.dll
28-05-2020 08:26 506.248 hostpolicy.dll
You can also prepare an image for Linux by replacing win-x64 with linux-x64 and then the output is:
Code: Select all
29-07-2020 16:16 44.552.454 test
28-05-2020 07:54 563.728 libhostfxr.so
28-05-2020 07:54 532.408 libhostpolicy.so
I hope you find this interesting.
Robert
And yes this will be included in the next build. Not with the VS project system, that will take a bit longer.