gpt4 book ai didi

C#动态编译和 "Microsoft.CSharp.dll"错误

转载 作者:太空狗 更新时间:2023-10-29 20:51:44 25 4
gpt4 key购买 nike

我做的例子可以查到here .所以我尝试在 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”程序集引用,无法编译动态操作。”我真的不明白那是什么,我忘了添加什么?

在我的引用资料中,我有: References of my project

感谢您的帮助。

Ps: 我在 MonoDevelop 上。

最佳答案

这对我有帮助。我正在使用 Xamarian Studio v5.8.1 (build 8) 编写 C# 程序。我只需右键单击“引用”->“编辑引用”->开始在搜索栏中输入“Microsoft”->选中“Microsoft.CSharp”旁边的框->然后单击“确定”。

之后我刚刚保存并运行了程序 - 一切都按预期进行!

关于C#动态编译和 "Microsoft.CSharp.dll"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11417047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com