如何在.Net Core 1.0中使用IronPython

时间:2016-05-22 18:26:09

标签: .net mono ironpython .net-core python.net

我试图将IronPython添加到.Net Core 1.0网络应用程序中,但是有问题可以访问ScriptRuntime类。当我尝试添加using IronPython;时,我收到错误消息,说无法找到IronPython。

我也遇到有关ScriptRuntime does not exist in the current context

的错误

注意:目前在OSX 10.11上使用Visual Studio Code

以下是我的project.json的依赖项和框架部分:

{
  "version": "1.0.0-*",
  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.Sqlite": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.NETCore.Platforms": "1.0.1-*",
    "Newtonsoft.Json": "8.0.3",
    "IronPython": "2.7.5",
    "IronPython.StdLib": "2.7.5"
  },
  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },
  "frameworks": {
    "dnx451": {},
    "dnxcore50": {}
  },
}

在我的控制器中,我有以下使用语句:

using System.IO;
using System.Diagnostics;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using MatrixSynthesisWebApp.Models;
using System.Dynamic;
using System.Runtime.CompilerServices;
using IronPython;

2 个答案:

答案 0 :(得分:3)

Svicks答案不是当前状态:

IronPython团队刚刚发布了支持mono和.net核心的IronPython 2.7.8测试版:

此处有更多信息:https://github.com/IronLanguages/ironpython2/releases

支持mono和.net核心的IronPython 3仍在进行中。

答案 1 :(得分:2)

我认为不可能在.Net Core上使用IronPython NuGet包。该软件包是为.Net Framework(和Silverlight)编译的,这意味着它无法从.Net Core中使用。

您可以考虑将IronPython移植到netstandard,该标准可以从。{3}}上的.Net Core中使用。

编辑:似乎最新版本的IronPython NuGet包支持.Net Core 2.x.所以看起来现在应该可以了。