问题描述
我正在做可以在这里找到的示例.所以我试图在 C# 脚本中运行 IronPython:
I'm doing the example that can be found here.So I'm trying to run IronPython in a C# script:
蟒蛇:
def hello(name):
print "Hello " + name + "! Welcome to IronPython!"
return
def add(x, y):
print "%i + %i = %i" % (x, y, (x + y))
return
def multiply(x, y):
print "%i * %i = %i" % (x, y, (x * y))
return
C#:
using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
using System;
namespace IntroIronPython
{
class IronPythonMain
{
static void Main(string[] args)
{
// Create a new ScriptRuntime for IronPython
Console.WriteLine("Loading IronPython Runtime...");
ScriptRuntime python = Python.CreateRuntime();
try
{
// Attempt to load the python file
Console.WriteLine("Loading Python File...");
// Create a Dynamic Type for our Python File
dynamic pyfile = python.UseFile("PythonFunctions.py");
Console.WriteLine("Python File Loaded!");
Console.WriteLine("Running Python Commands...
");
// Call the hello(name) function
pyfile.hello("Urda");
…
从这里我有这个错误:如果没有Microsoft.CSharp.dll"程序集引用,则无法编译动态操作."我真的不明白那是什么意思,我忘了添加什么?
And from here I have this error:"Dynamic Operation cannot be compiled without "Microsoft.CSharp.dll" assembly reference."And I seriously don't understand what that is about, what did I forget to add?
在我的参考资料中,我有:
In my references I have:
感谢您的帮助.
Ps:我在 MonoDevelop 上.
Ps: I'm on MonoDevelop.
推荐答案
好的.基本上,我的错误与我从错误的平台添加 IronPython 程序集有关.验证:
Ok. Basically, my mistake was linked to the fact that I added my IronPython assemblies from the wrong platform.Verify that:
目标框架:4.0
Target Framework: 4.0
在 [IronPython-2.7.3]->[Platforms]->[Net40] 中添加 IronPython 提供的所有程序集.
Add all the assemblies provided by IronPython in [IronPython-2.7.3]->[Platforms]->[Net40].
感谢所有给我建议的人.
Thx to everyone who gave me advices.
Ps:现在,当然,还有另一个问题……但这不再是关于那个话题了.
Ps:Now, of course, there is another problem… But it's not about that topic anymore.
这篇关于C# 动态编译和“Microsoft.CSharp.dll"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!