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.