Using Visual Studio to Develop Mercurial

Modern versions of Microsoft's Visual Studio support Python Tools for Visual Studio (PTVS), which makes it possible to develop Python applications - including Mercurial - inside Visual Studio.

Obtaining Visual Studio

Visual Studio Community is a version of Visual Studio free for open source projects (like Mercurial). We recommend installing it.

At the time this was written, Visual Studio 2015 was the latest available version and is known to work with these instructions.

Follow the PTVS Installation Instructions to install Python support when installing Visual Studio.

Installing Python

PTVS won't install Python for you: you'll need to install it yourself.

Find a link to a Python 2.7 MSI installer from https://www.python.org/downloads/windows/. Mercurial supports both 32-bit and 64-bit Python on Windows.

Quick link to Python 2.7.10 installers: 32-bit, 64-bit.

We'll assume Python was installed to the default location of C:\Python27.

Obtain Mercurial Source Code

Before configuring a Visual Studio solution, you'll need to obtain the Mercurial source code. We assume you know how to do that.

Creating a Visual Studio Solution

To develop Mercurial inside Visual Studio, you'll need to create a Visual Studio solution. Follow this procedure:

  1. Open Visual Studio
  2. Find and click the link to create a New Project... (File -> New -> Project... or it will be somewhere on the start screen).

  3. In the available templates tree list, there should be a Python section. Expand it and select From existing Python code.

  4. Set the project Name text box to "hg" or similar.

  5. Adjust the Location text box if desired (it doesn't matter where the solution/project is located).

  6. Click OK. You should see a Welcome to the Create New Project from Existing Python Code Wizard window.

  7. Point it at the location of your Mercurial source code. e.g. C:\Users\me\src\hg
  8. For the include files filter, replace the contents with *.h;*.c;*.t;*.txt

  9. Click Next

  10. From the Python interpreter dropdown, make sure an appropriate interpreter is selected. Or use the global default if it is acceptable.
  11. It should ask for a file to run when F5 is pressed. It likely defaults to setup.py. This is fine for now.
  12. Click Next

  13. It will ask you where to save the project. The default location inside the hg source directory is probably fine.
  14. The Detect Virtual Environments checkbox is likely checked. The value doesn't matter to use. Leave the default.
  15. Click Finish
  16. After a few seconds, the Solution Explorer should be visible and the basic directory structure of the Mercurial source directory should be present.

  17. At this point, you should be able to open .py files and IntelliSense should work

The Visual Studio project won't build or launch Mercurial yet. For the best experience, we'll need to figure out how to get Visual Studio to do these things so interactive debugging and profiling works.


CategoryWindows

VisualStudio (last edited 2015-08-01 19:38:25 by GregorySzorc)