Projects

Python Tools supports the Visual Studio project system. Project files for Python projects are .pyproj files. Like all Visual Studio languages, Python project files are referenced from a solution which can contain one or more project files from varying languages.

i.solution.explorer.png Projects include a start-up file which is the file that runs when you start with debugging or execute your project in the interactive window. This file is indicated by the green play button on the file icon. You can change this file either by right clicking and selecting “Set as Startup File” or by setting the startup file in the project’s properties.


 

 

 

Project Types

 

Note: currently, for the various project types to show up, you need to install the relevant supporting software (eg HPC SDK for the MPI projects, IronPython for .Net projects, ...)

Console Application

This is a simple application or script which is launched as “ipy.exe Program.py”. The program will have a console window for input and output. If you use Execute in Python Interactive, input and output occur in the interactive as if it were a console window.

IronPython Silverlight Web Page

This is an IronPython application which will run in the web browser using Silverlight. Your script code is written in a .py file that a web page includes using a <script type=”text/python” src=”…”> tag. A boilerplate script tag pulls down some JavaScript code which initializes IronPython running inside of Silverlight. From there your Python code can interact with the DOM. Note: Silverlight support is very preliminary at this time.

WPF Application

This is an application which is launched as “ipyw.exe Program.py”. This program will not have a console window and includes a template which creates a Windows Presentation Foundation application. The code and design are separated with the markup being stored in a .XAML file. There is a WYSIWIG designer which enables drag and drop editing of the design. Python code can be used to wire up event handling.

Windows Forms Application

This is an application which is launched as “ipyw.exe Program.py”. The program will not have a console window. A typical usage of this is to start a Windows Forms application. Python Tools currently does not provide any WYSIWIG support for developing Windows Forms applications. Instead you’ll need to write the logic to create the UI in Python (see the IronPython tutorial for examples).

Lightweight Usage Project-free

Python Tools also supports editing your code without a project system. You can open any files on disk and start editing them. Python Tools will automatically include other files and packages in the same directory in its analysis, so you’ll get member completion and help without being required to create a project file.

Create Project from Existing Files

If you already have existing Python code, you can easily create a new project without having to move it around.  In the New Project window select "From Existing Python Code":

New Project window

This will display the following wizard, where you can choose the path containing your existing code, a filter to include specific file types, and any search paths that your project requires.

New Project from Existing Code Wizard step one

On the next page, you can choose the interpreter to associate with this project and the file to run when you press F5. (Only files in the root of the folder tree are shown, so if the one you want is not there, don't choose anything for now and set it later.)

New Project from Existing Code Wizard step two

Click Finish and your project will be created. If you want to move the .pyproj file somewhere else at this point, select it in Solution Explorer and choose 'File->Save As'. Moving the .pyproj this way will update the file references, so we don't have to copy any code files around. (Though this does mean that changing/renaming/deleting files through the project will update the originals, so if you want a copy you should make one before creating the project.)

Project Features

Linked Files

Linked files appear in solution explorer as normal files with a shortcut icon overlayed on top of them. Linked files can exist either at the top-level of the project or embedded within an arbitrary folder structure.

Linked files are specified in the .pyproj file using the normal <Compile Include> tag. They can be implicit linked files if they use a relative path outside of the directory structure or they can be explicit link files by specifying their path within solution explorer:

  <Compile Include="..\test2.py">
      <Link>X\test2.py</Link>
  </Compile>

Linked files specified in a project file will be ignored under the following conditions:

  • When the linked file contains Link metadata and the path specified in the Include attribute lives within the project directory.
  • When the linked file duplicates a file which exists within the project hierarchy
  • When the linked file contains Link metadata and the Link path is a relative path outside of the solution explorer hierarchy.
  • The link path is rooted

Adding Existing Items as Links

To add an existing item as a link the user can use the Project->Add Existing Item menu (or the context menu), select a file, and choose “Add as Link” from the drop down on the Add button. This will create a link at the existing selected level in Solution Explorer. When creating a link to a file which lives within the project directory or a child directory the file will be added to the project in the correct location as a normal file instead of a link.

Creating New Linked Files

A user can create a linked file via the user interface by doing File->Save As for a file which exists somewhere within the project hierarchy. The old file node in the project will be removed and replaced by a linked file node (the link is created at the same location in the hierarchy as the previous node). The old file on disk will not be deleted.

Converting Linked Files to Normal Files

A linked file can be converted into a normal file by doing File->Save As and saving the file into a location within the project hierarchy. The node in the project hierarchy will be moved into the appropriate location in solution explorer

Moving Linked Files

When using the solution explorer UI to move a linked file the end result is that the link moves but the file on disk remains unaffected. If the file was open in the editor the file will remain open.

Deleting Linked Files

When using the solution explorer UI to delete a linked file the end result is that the link is removed from the project and the file remains on disk. The user is not prompted for the option to delete the file.

Renaming Linked Files

Renaming of linked files will not be allowed. Both renaming on the node as well as renaming via project properties will be disallowed. Attempting to rename a file via the automation API will raise an InvalidOperationException.

Duplicate Linked Files and Normal Files

If a project contains both a linked file and a normal file at the same level of the solution hierarchy the linked file will be renamed. When adding a new file or link to the project if an existing file or link exists at the same level in the hierarchy then the addition will not be allowed. Additionally if a link to a file already exists anywhere within the project a second link will not be permitted to be added. If the user modifies the project by hand to introduce duplicate links then only one link will be added when loading the project file.

Last edited Oct 30, 2012 at 11:19 PM by huguesv, version 15

Comments

No comments yet.