我正在做可以找到的示例here。 所以我想在C#腳本運行的IronPython:C#動態編譯和「Microsoft.CSharp.dll」錯誤
的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」程序集引用。「 我真的不明白這是關於什麼,我忘了添加什麼?
在我引用我有:
THX對您有所幫助。
Ps:我在MonoDevelop上。
確保您將自己的答案標記爲解決方案,以便將來的訪問者可以看到您解決了問題!此外,我很高興你找到並選擇使用我的例子:) – Urda 2012-07-12 18:57:08
這也是我的問題。我已經使用Visual Studio C#2010 Express中的「.NET」選項卡添加了我的引用。我認爲出現的原始文件可能只來自'Net35'目錄。請注意添加引用對話框中的「路徑」。當我從IronPython 2.7 \ Platforms \ Net40中添加它們時,構建成功,並且現在兩組程序集都出現在添加引用中的.Net選項卡上。 (之前也可能是這種情況,我只是沒有注意到)。 – cod3monk3y 2013-12-10 18:10:39