Используемая версия:
4.10.0-3.final
Шаги по воспроизведению:
Я создал новое консольное приложение .NET 8 (опубликуйте AOT профиль) с базовой настройкой проекта:
Код: Выделить всё
Exe
net8.0
enable
enable
true
true
Код: Выделить всё
public static class Foo
{
public static string Name { get; set; } = "Bar";
}
Код: Выделить всё
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
namespace RoslynTest
{
internal class Program
{
static async Task Main(string[] args)
{
try
{
var codeToEval =
@"
int test = 0;
var count = test + 15;
count++;
Console.WriteLine(count);
Console.WriteLine(Foo.Name);
";
var options = ScriptOptions.Default;
options = options
.WithImports("System", "RoslynTest.Test")
.AddReferences("RoslynTest");
var result = await CSharpScript.EvaluateAsync(codeToEval, options);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
Код: Выделить всё
16
Bar
Код: Выделить всё
16
Bar
При публикации с использованием AOT с параметрами:
Код: Выделить всё
Configuration: Release
Deployment mode: Self-contained
Target runtime: win-x64
Код: Выделить всё
Operation is not supported on this platform.С помощью выходных данных я определил, в чем проблема:
Код: Выделить всё
CSharpScript.EvaluateAsync(codeToEval, options);Подробнее здесь: https://stackoverflow.com/questions/785 ... lished-aot
Мобильная версия