Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LA nuget updata
#1
I am trying to create a Docker image that uses the LA library from NuGet, but I’m getting the following error. It seems that the version hasn’t been updated.
Could you release a cross-platform version of the library? I want to use some of its classes in Docker.
In order to stay consistent with the LA desktop version, could the LA library be updated to 9.0? Thank you.

NuGet Gallery | LibreAutomate 1.12.0

 => ERROR [build 4/6] RUN dotnet restore                                                                                                                               9.6s
------
 > [build 4/6] RUN dotnet restore:
1.154   Determining projects to restore...
9.379 /src/dotnet_runner.csproj : error NU1202: Package LibreAutomate 1.12.0 is not compatible with net9.0 (.NETCoreApp,Version=v9.0). Package LibreAutomate 1.12.0 supports:
9.379 /src/dotnet_runner.csproj : error NU1202:   - net8.0-windows7.0 (.NETCoreApp,Version=v8.0)
9.379 /src/dotnet_runner.csproj : error NU1202:   - net9.0-windows7.0 (.NETCoreApp,Version=v9.0)
9.413   Failed to restore /src/dotnet_runner.csproj (in 8.02 sec).

If don’t use the LA library, much of the code from LA would need to be manually converted to generic C# code to be usable, for example the code in the following link:
https://www.libreautomate.com/forum/show...p?tid=7491
#2
The LA NuGet package version is OK, it is for .NET 9, but it can be used only on Windows. To make it cross-platform would need to remove all its essential features; what's left is worth nothing.
#3
Thanks for your explanation.
Are the SQLite , Internet , HttpServerSession classes in LA cross-platform? I want to use the code from the following two links in Docker.

https://www.libreautomate.com/forum/show...p?tid=7491
Run script on another computer; HTTP server | LibreAutomate
#4
Likely they can be made cross-platform, if replaced LA library functions used in them.

sqlite - would need a private sqlite3.dll for each platform.
internet and HttpServerSession - probably all used API are cross-platform. Not sure.
#5
1. Regarding the CsScript.cs class, after I modified the code into generic C#, it worked very well in Docker.
Additionally, the reason I want to use the SQLite class in LA is because of the following statement.
Quote://use ref.db if exists. The process uses less memory, eg 165 MB -> 65 MB. And slightly faster.

2. I need to package the Internet class in LA and its related classes into a file named Au.dll(It would be best if the SQLite class could also be included). I’d like to know what the simplest solution to achieve this goal is. By using the F12 hotkey, I found some information, and the video demonstration is as follows.
https://github.com/xhzkp/temp_video/issues/31
#6
1. With sqlite difficult to make cross-platform. Try this instead.
 
Code:
Copy      Help
    /// <summary>
    ///
Creates <b>MetadataReference</b> for all .NET assemblies and Au.dll.
    /// </summary>
    static List<MetadataReference> _GetRefs() {
        var r = new List<MetadataReference>();
#if !true //use ref.db (from LA) if exists. The process uses less memory, eg 160 MB -> 50 MB. And slightly faster.
        var rdb = folders.ThisAppBS + "ref.db"; //if role exeProgram, copy it to the exe folder from LA folder. Else exists.
        if (filesystem.exists(rdb)) {
            using var db = new sqlite(rdb, SLFlags.SQLITE_OPEN_READONLY);
            using var stat = db.Statement("SELECT * FROM ref");
            while (stat.Step()) r.Add(MetadataReference.CreateFromImage(stat.GetArray<byte>(1), filePath: stat.GetText(0)));
            r.Add(MetadataReference.CreateFromFile(folders.ThisAppBS + "Au.dll"));
        } else {
            var s = AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") as string;
            foreach (var v in s.Split(';', StringSplitOptions.RemoveEmptyEntries)) {
                if (v.Starts(folders.ThisAppBS, true) && !v.Ends(@"\Au.dll", true)) continue;
                r.Add(MetadataReference.CreateFromFile(v));
            }
        }
#elif !true //use .NET run-time assemblies. Uses much memory because they contain code; in reference assemblies code is removed.
        var s = AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") as string;
        foreach (var v in s.Split(';', StringSplitOptions.RemoveEmptyEntries)) {
            if (v.Starts(folders.ThisAppBS, true) && !v.Ends(@"\Au.dll", true)) continue;
            r.Add(MetadataReference.CreateFromFile(v));
        }
#elif true //use downloaded .NET reference assemblies. Uses less memory than with ref.db.
        
        //This is supposed to be a cross-platform version. Tested only on Windows.
        //It does not use/support the LA library (Au.dll) and .NET Windows-specific stuff (WPF, winforms, registry etc).
        
        //Before this can be used:
        //Go to https://www.nuget.org/packages/Microsoft.NETCore.App.Ref
        //Select the newest version for your major .NET version (eg version 9.0.8 for .NET 9).
        //Download package (a link at the right). Don't extract.
        //Edit the nupkg variable value if need.

        
        string nupkg = folders.Downloads + "microsoft.netcore.app.ref.9.0.8.nupkg"; //the downloaded file. Change if need.
        
        using var za = ZipFile.OpenRead(nupkg);
        var dir = $"ref/net{Environment.Version.ToString(2)}/";
        foreach (var e in za.Entries) {
            var path = e.FullName;
            if (path.Ends(".dll") && path.Starts(dir)) {
                using var ds = e.Open();
                using var ms = new MemoryStream();
                ds.CopyTo(ms);
                r.Add(MetadataReference.CreateFromImage(ms.ToArray(), filePath: e.Name));
            };
        }

#endif
        return r;
    }

Example.
 
Code:
Copy      Help
// script "test CsScript ref from NuGet.cs"
/*/ c CsScript.cs; /*/

print.clear();

string code = """
using System;

foreach (var v in args) Console.WriteLine(v);
"""
;

var c = CsScript.Compile(code);
if (c == null) return;

print.redirectConsoleOutput = true; //need this if the script contains Console.WriteLine and the caller app isn't console
c.Run("command", "line", "arguments");


2. Use Visual Studio or VSCode or Rider. Create new .NET library project. Set output assembly name. Add internet.cs to it. Try to build. It will output errors where LA library functions used. Replace these codes and try build again.

Or don't use LA library functions for internet. They just make the `HttpClient` class a little easier to use. Use `HttpClient` directly. AI can help you.


Forum Jump:


Users browsing this thread: 1 Guest(s)