我正在做可以找到的示例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