Visual Studio 2010的官方语言扩展示例是Iron Python集成示例。
您可以从这里下载它:IronPython 集成。这里有一个相关的文档:Visual Studio IronPython Integration Deep Dive
不幸的是,据我所知,此示例并未针对 Visual Studio 2012 进行更新。但是,这里是将其转换为 Visual Studio 2012 的步骤。
- 从此处安装 Visual Studio 2012 SDK:Microsoft Visual Studio 2012 SDK
- 下载 Iron Python 集成示例,提取到磁盘上的某个位置
- 打开
IronPython.sln
,并接受所有升级转换
- 将项目的平台目标从更改
AnyCpu
为x86
- 某些项目对 Visual Studio 11 程序集(针对 .NET 4.5 构建)的引用不正确(自动提示),因此它们不会按原样编译。将它们改回 Visual Studio 10 程序集。例如,IronPython.Console 项目中的 Microsoft.VisualStudio.ExtensibilityHosting.dll 需要指向
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
.
- 将
IronPython.Project
项目定义为启动项目,并更新其调试参数:启动操作需要启动C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe
(VS 2012 shell)外部程序,而不是C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
默认设置的(VS 2010 shell)外部程序。命令行参数应设置为/RootSuffix Exp
IronPython.targets
更新所有基本模板以使用 VS 2012 目录而不是仅使用 VS 2010 目录:在所有 .pyproj 文件中搜索字符串并添加 VS 2012 案例,如下所示:
前:
<PropertyGroup>
<!-- Set the IronPythonPath property by proving in different locations where Iron Python could be installed -->
<!-- Regular LocalAppData -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Experimental LocalAppData -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\10.0Exp\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\10.0Exp\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Integrated Shell -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(MSBuildExtensionsPath)\Microsoft\IronPython Studio 2010\1.0\IronPython.targets')">$(MSBuildExtensionsPath)\Microsoft\IronPython Studio 2010\1.0</IronPythonPath>
</PropertyGroup>
后:
<PropertyGroup>
<!-- Set the IronPythonPath property by proving in different locations where Iron Python could be installed -->
<!-- Regular LocalAppData -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\10.0\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Experimental LocalAppData -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\10.0Exp\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\10.0Exp\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Regular LocalAppData VS10212 -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\11.0\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\11.0\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Experimental LocalAppData VS2012-->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(LocalAppData)\Microsoft\VisualStudio\11.0Exp\Extensions\Microsoft\IronPython\1.0\IronPython.targets')">$(LocalAppData)\Microsoft\VisualStudio\11.0Exp\Extensions\Microsoft\IronPython\1.0</IronPythonPath>
<!-- Integrated Shell -->
<IronPythonPath Condition=" '$(IronPythonPath)' == '' AND Exists('$(MSBuildExtensionsPath)\Microsoft\IronPython Studio 2010\1.0\IronPython.targets')">$(MSBuildExtensionsPath)\Microsoft\IronPython Studio 2010\1.0</IronPythonPath>
</PropertyGroup>
就是这样。编译并运行(由于注册的谜团,第一次都需要一段时间)。
以下是从 Visual Studio 2012 启动新 Iron Python 项目时的结果:
并在构建时: