我正在做可以在这里找到的例子。所以我试图在 C# 脚本中运行 IronPython:
Python:
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...\n");
// Call the hello(name) function
pyfile.hello("Urda");
…
从这里我有这个错误:“没有“Microsoft.CSharp.dll”程序集引用,无法编译动态操作。” 而且我真的不明白那是什么,我忘了添加什么?
在我的参考文献中,我有:
谢谢你的帮助。
Ps:我在 MonoDevelop 上。