Roslyn 可以用于 VB.NET 脚本吗?
我正在为我的应用程序创建一个脚本编辑器,我希望它能够使用 Roslyn 运行 C# 和 VB.NET 脚本.我通过使用 Microsoft.CodeAnalysis.CSharp.Scripting
程序集/命名空间中的 CSharpScript
类来使用 C#,但是没有等效的 VisualBasicScript
我能找到的类,也不是 Microsoft.CodeAnalysis.VisualBasic.Scripting
程序集.我在网上搜索过,没有发现任何关于运行 VB.NET 脚本的有用信息,而且 Roslyn github 站点上的所有示例都是 C# 特定的.我是不是遗漏了什么,或者对运行 VB.NET 脚本的支持根本不存在,就像它对 C# 脚本所做的那样?
I'm creating a script editor for my application, and I'd like to have it be able to run both C# and VB.NET scripts using Roslyn. I got this working with C# by using the CSharpScript
class in the Microsoft.CodeAnalysis.CSharp.Scripting
assembly/namespace, however there is no equivalent VisualBasicScript
class that I can find, nor a Microsoft.CodeAnalysis.VisualBasic.Scripting
assembly. I've scoured the web and can find nothing useful about running VB.NET scripts, and all the samples on the Roslyn github site are C#-specific. Am I missing something, or does support for running VB.NET scripts simply not exist the way it does for C# scripts?
目前没有 Visual Basic Scripting可用,大概是因为尚未完成.
但是它的来源是 Roslyn repo,所以你可以尝试自己构建它.
But its source is is the Roslyn repo, so you could try building it yourself.
当我这样做时,如下代码对我有用:
When I do that, code like the following works for me:
Dim result = VisualBasicScript.RunAsync("Dim result = 1+1").Result
For Each variable In result.Variables
Console.WriteLine($"{variable.Name}: {variable.Value}")
Next
但是这段代码对我不起作用(编译脚本时失败):
But this code does not work for me (it fails when compiling the script):
Console.WriteLine(VisualBasicScript.EvaluateAsync("1+1").Result)
我不确定这是因为它还没有完成,还是故意与 C# 脚本有所不同.
I'm not sure whether this is because it's not finished, or whether it's intentional difference from C# scripting.