Export (0) Print
Expand All

IronPython Compiler Task Sample

Visual Studio 2005
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This sample builds an MSBuild task that invokes the IronPython compiler, and installs an MSBuild target that references this task. This makes it possible for MSBuild to build an IronPython project given the .pyproj project file for that project.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices.  Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

This sample illustrates:

  • Creating an MSBuild task that invokes a compiler.

  • Creating an MSBuild target that takes advantage of Microsoft.Common.Targets.

  • Deploying the task and target in such a way that they can be used from anywhere on the computer.

MSBuild maintains a standard location for task and target files called the MSBuild extensions path. It typically is located at

C:Program Files\MSBuild\Microsoft\<your language>\<your version>.

For IronPython, this location typically would be

C:Program Files\MSBuild\Microsoft\IronPython\1.0.

The IronPythonCompilerTask project builds the IronPython.dll task at this location and copies the IronPython.targets target file there. By using this standard location, MSBuild can build IronPython .pyproj project files anywhere on the computer.

NoteNote

The MSBuild extensions path is specified in two places in the IronPython solution. To integrate a new language, you must update the <language> and <version> of these MSBuild extension paths:

  • The <DeployDestination> tag in the IronPythonCompilerTask.csproj file.

  • The <Import> tag in the IronPython project templates.

Once you build the IronPythonCompilerTask project, you can run MSBuild from the command line to build a .pyproj project file. This technique is useful if you are implementing a language project system and would like to test the compiler before the system is complete. You can adapt a project file from some other language project to test the build system.

NoteNote

The IronPython project templates reference the IronPython.targets file. Because of this, the PythonProject project depends on the IronPythonCompilerTask project.

To build the sample

  1. Open the IronPython.sln solution in the <Installation Path>\VisualStudioIntegration\Samples\IronPythonIntegration folder.

    NoteNote

    This sample includes the IronPythonCompilerTask project, which contains an overview document with detailed implementation notes. To open it, right-click MSBuildTasks\Overview.xml, and then click View in Browser.

  2. On the Build menu, click Build IronPythonCompilerTask.

    The IronPython task and target files are built in the MSBuild standard location.

To see the sample's functionality

  1. Examine the MSBuild standard location and verify that the files IronPython.dll and IronPython.targets are present.

  2. Use MSBuild to build an IronPython project. See the IronPython Project System Sample for more information.

Demonstrates

Classes Interfaces

Task

ITask

See Also

Other Resources

IronPython Samples

Community Additions

ADD
Show:
© 2015 Microsoft