在 UWP 中使用 Roslyn 脚本
Using Roslyn scripting in UWP
我有以下代码段。
var script = CSharpScript.Create("int x = 12;");
var result = await script.RunAsync();
var variable = result.GetVariable("x");
int value = (int)variable.Value;
它在第二行崩溃并显示以下内容:
Could not load file or assembly 'System.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'. The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
这是一个 UWP 应用程序,我正在尝试使用 Microsoft.CodeAnalysis.CSharp.Scripting
库。我通过 NuGet 安装了这个包。应用编译和部署,但在此代码的第二行崩溃。
显然,问题出在 System.Core
DLL 中,它与我的应用程序 (4.6) 部署的版本和库使用的版本 (4.0) 之间存在冲突。有人对此有解决方案吗?有没有办法指定要使用的库版本或目标框架(即使我使用的是 UWP)?
通过我这边的测试,我得到了以下异常:
System.NotSupportedException: Assembly.Load(byte[], ...) is not supported in AppX
和你的不一样。我用了 Microsoft.CodeAnalysis.CSharp.Scripting 2.3.2
实际上脚本 APIs 不能在通用 Windows 应用程序和 .NET Native 中使用,因为应用程序模型不支持加载运行时生成的代码。详情请参考 this article 的 "Supported Platforms" 部分。因此,目前您不应该能够为 UWP 使用脚本 API。
我有以下代码段。
var script = CSharpScript.Create("int x = 12;");
var result = await script.RunAsync();
var variable = result.GetVariable("x");
int value = (int)variable.Value;
它在第二行崩溃并显示以下内容:
Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
这是一个 UWP 应用程序,我正在尝试使用 Microsoft.CodeAnalysis.CSharp.Scripting
库。我通过 NuGet 安装了这个包。应用编译和部署,但在此代码的第二行崩溃。
显然,问题出在 System.Core
DLL 中,它与我的应用程序 (4.6) 部署的版本和库使用的版本 (4.0) 之间存在冲突。有人对此有解决方案吗?有没有办法指定要使用的库版本或目标框架(即使我使用的是 UWP)?
通过我这边的测试,我得到了以下异常:
System.NotSupportedException: Assembly.Load(byte[], ...) is not supported in AppX
和你的不一样。我用了 Microsoft.CodeAnalysis.CSharp.Scripting 2.3.2
实际上脚本 APIs 不能在通用 Windows 应用程序和 .NET Native 中使用,因为应用程序模型不支持加载运行时生成的代码。详情请参考 this article 的 "Supported Platforms" 部分。因此,目前您不应该能够为 UWP 使用脚本 API。