ssx*_*ssx 6 c# ironpython dynamic .net-assembly
我正在做的例子可以在这里找到.所以我试图在C#脚本中运行IronPython:
蟒蛇:
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
Run Code Online (Sandbox Code Playgroud)
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");
…
Run Code Online (Sandbox Code Playgroud)
从这里我有这个错误:"没有"Microsoft.CSharp.dll"程序集引用,无法编译动态操作." 我真的不明白那是什么,我忘了添加什么?
在我的参考资料中,我有:

谢谢你的帮助.
Ps:我在MonoDevelop上.
tyl*_*ell 12
这对我有所帮助.我正在使用Xamarian Studio v5.8.1(build 8)编写C#程序.我只需右键单击"引用" - >"编辑引用" - >开始在搜索栏中键入"Microsoft" - >选中"Microsoft.CSharp" - >旁边的复选框,然后单击"确定".
我刚刚保存并运行程序 - 一切都按预期工作!
好的。基本上,我的错误与我从错误的平台添加 IronPython 程序集有关。\n验证:
\n\n目标框架:4.0
在[IronPython-2.7.3]->[Platforms]->[Net40]中添加IronPython提供的所有程序集。
感谢所有给我建议的人。
\n\nPs:当然,现在还有另一个问题\xe2\x80\xa6 但已经不再是那个话题了。
\n