WeihanLi / dotnet-exec

dotnet execute with custom entry point, another dotnet run without project file
https://weihanli.github.io/dotnet-exec/
Apache License 2.0
51 stars 5 forks source link

thiry-party linqpad/netpad execute support #20

Closed WeihanLi closed 4 months ago

WeihanLi commented 7 months ago

add support for linqpad/netpad script execute

WeihanLi commented 5 months ago

linqpad script sample

<Query Kind="Statements">
  <NuGetReference>Microsoft.ML.OnnxRuntimeGenAI</NuGetReference>
  <NuGetReference>WeihanLi.Common</NuGetReference>
  <Namespace>WeihanLi.Common</Namespace>
  <Namespace>WeihanLi.Common.Helpers</Namespace>
  <Namespace>WeihanLi.Common.Http</Namespace>
  <Namespace>WeihanLi.Extensions</Namespace>
  <Namespace>Microsoft.ML.OnnxRuntimeGenAI</Namespace>
</Query>

Console.WriteLine("--------------------");
<Query Kind="Program">
  <NuGetReference>WeihanLi.Common</NuGetReference>
  <Namespace>WeihanLi.Common</Namespace>
  <Namespace>WeihanLi.Common.Helpers</Namespace>
  <Namespace>WeihanLi.Common.Http</Namespace>
  <Namespace>WeihanLi.Extensions</Namespace>
</Query>

void Main()
{
    Console.WriteLine("Hello World");
}

// You can define other methods, fields, classes and namespaces here
<Query Kind="Expression">
  <NuGetReference>WeihanLi.Common</NuGetReference>
  <Namespace>WeihanLi.Common</Namespace>
  <Namespace>WeihanLi.Common.Helpers</Namespace>
  <Namespace>WeihanLi.Common.Http</Namespace>
  <Namespace>WeihanLi.Extensions</Namespace>
</Query>

123 + 321
WeihanLi commented 4 months ago

netpad sample

1fbfda72-351f-4dfe-b163-657e3e05f9bc
{"config":{"kind":"Program","targetFrameworkVersion":"DotNet8","optimizationLevel":"Debug","useAspNet":false,"namespaces":["System","System.Collections","System.Collections.Generic","System.Data","System.Diagnostics","System.IO","System.Linq","System.Linq.Expressions","System.Net.Http","System.Reflection","System.Text","System.Text.RegularExpressions","System.Threading","System.Threading.Tasks","System.Xml","System.Xml.Linq","System.Xml.XPath","System.Text.Json","System.Text.Json.Nodes"],"references":[{"discriminator":"PackageReference","packageId":"WeihanLi.Common","version":"1.0.66","title":"WeihanLi.Common"}]},"dataConnection":null}
#Code
using WeihanLi.Common;

var filePath = @"blog-articles.json";

using var fs = File.OpenRead(filePath);

var services = Guard.NotNull(JsonSerializer.Deserialize<JsonObject[]>(fs))
.Select(o => o["articleId"]?.GetValue<int>())
.ToHashSet();

Console.WriteLine(string.Join(",", services.Select(s=> $"{s}")));

ScriptSerializer: https://github.com/tareqimbasher/NetPad/blob/b48529cab236d8607bb67ee211154239e72de757/src/Apps/NetPad.Apps.Common/Scripts/ScriptSerializer.cs#L10

WeihanLi commented 4 months ago

supported in 0.22.0