Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LA nuget updata
#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.


Messages In This Thread
LA nuget updata - by Davider - 09-08-2025, 01:04 PM
RE: LA nuget updata - by Gintaras - 09-08-2025, 02:32 PM
RE: LA nuget updata - by Davider - 09-08-2025, 02:54 PM
RE: LA nuget updata - by Gintaras - 09-08-2025, 03:17 PM
RE: LA nuget updata - by Davider - 09-08-2025, 10:16 PM
RE: LA nuget updata - by Gintaras - 09-09-2025, 06:13 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)