简体   繁体   English

Roslyn不支持脚本`dynamic`的脚本,仅适用于mono,但是在DLL上mono失败

[英]for scriptcs `dynamic` is not supported by Roslyn and available only with mono, but mono fails on DLL

I'm try to load pythonnet runtime dll from scriptcs and it does not work with roslyn backend because dynamic is not supported in Roslyn, but mono backend chokes with the following error: 我正在尝试从scriptcs加载pythonnet运行时dll,并且它不适用于roslyn后端,因为Roslyn不支持dynamic,但是mono后端阻塞了以下错误:

$ scriptcs -modules mono
scriptcs (ctrl-c to exit or :help for help)

> #r "F:\Python\Python27\Lib\site-packages\Python.Runtime.dll"
error CS0009: Metadata file `F:\Python\Python27\Lib\site-packages\Python.Runtime.dll' does not contain valid metadata

Question: 题:


How can I get Mono backend of scriptcs working with Python.Runtime.DLL? 如何获得使用Python.Runtime.DLL的脚本的Mono后端? Do I need to load any DLLs before that? 在此之前我是否需要加载任何DLL? Does the Python.Runtime.DLL has to be compiled with Mono support or .NET is fine? 是否必须在Mono支持下编译Python.Runtime.DLL或.NET很好?

This error (CS0009 with mono compiler) is quite generic and means "something wrong" with given assembly, so quite hard to debug. 此错误(带有Mono编译器的CS0009)非常笼统,在给定的程序集中表示“有问题”,因此很难调试。 One way to proceed is indeed compile under mono. 一种进行的方法确实是在mono下编译。 If you download their source code ( https://github.com/pythonnet ) you will find instructions on how to do that (look at pythonnet\\src\\monoclr\\README.txt also). 如果下载其源代码( https://github.com/pythonnet ),则会找到有关如何执行此操作的说明(另请参阅pythonnet \\ src \\ monoclr \\ README.txt)。

However, depending on your goals, you can consider using IronPython instead, which is officially supported by mono and runs out of the box. 但是,根据您的目标,您可以考虑使用IronPython代替,IronPython得到了Mono的正式支持,并且可以立即使用。 Example below assumes you downloaded zip of IronPython and extracted it somewhere: 下面的示例假定您下载了IronPython的zip并将其解压缩到某处:

scriptcs -modules mono
scriptcs (ctrl-c to exit or :help for help)
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\IronPython.dll"
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\Microsoft.Dynamic.dll"
> #r "G:\dev_tools\IronPython-2.7.5\IronPython-2.7.5\Microsoft.Scripting.dll"
> using System;
> using System.IO;
> using IronPython.Hosting;
> using Microsoft.Scripting;
> using Microsoft.Scripting;
> using Microsoft.Scripting.Hosting;
> string script = "print 'hello world'";
> var engine = Python.CreateEngine();
> var scope = engine.CreateScope();
> var source = engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
> var compiled = source.Compile();
> var result = compiled.Execute(scope);
hello world
>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM