Can Roslyn be used for VB.NET scripting?

孤街醉人 提交于 2019-12-12 17:50:17

问题


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?


回答1:


Visual Basic Scripting is not currently available, presumably because it's not finished.

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)

I'm not sure whether this is because it's not finished, or whether it's intentional difference from C# scripting.



来源:https://stackoverflow.com/questions/37670024/can-roslyn-be-used-for-vb-net-scripting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!