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.
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.
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:
- Open Visual Studio
Find and click the link to create a New Project... (File -> New -> Project... or it will be somewhere on the start screen).
In the available templates tree list, there should be a Python section. Expand it and select From existing Python code.
Set the project Name text box to "hg" or similar.
Adjust the Location text box if desired (it doesn't matter where the solution/project is located).
Click OK. You should see a Welcome to the Create New Project from Existing Python Code Wizard window.
- Point it at the location of your Mercurial source code. e.g. C:\Users\me\src\hg
For the include files filter, replace the contents with *.h;*.c;*.t;*.txt
- From the Python interpreter dropdown, make sure an appropriate interpreter is selected. Or use the global default if it is acceptable.
- It should ask for a file to run when F5 is pressed. It likely defaults to setup.py. This is fine for now.
- It will ask you where to save the project. The default location inside the hg source directory is probably fine.
- The Detect Virtual Environments checkbox is likely checked. The value doesn't matter to use. Leave the default.
- Click Finish
After a few seconds, the Solution Explorer should be visible and the basic directory structure of the Mercurial source directory should be present.
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.