-
Notifications
You must be signed in to change notification settings - Fork 675
Build and Debug Instructions for PTVS
First, you will require a local copy of our Git repository. It can be cloned from https://github.com/Microsoft/PTVS.git. (If you're behind a corporate firewall you may need to enter your proxy settings.)
Branch Selection:
- For Dev17 (Visual Studio 2022): Check out the
release/dev17branch - For Dev18 (Visual Studio 2026): Check out the
mainbranch
If you intend to contribute back to PTVS, you should Create a Fork and use the source URL provided there. Pull requests associated with an issue or feature request are the preferred way for making contributions.
- Install Visual Studio 2022 Preview Community edition or higher
- Install the following workloads:
- .NET desktop development
- Desktop development with C++
- Visual Studio extension development
- ASP.NET and web development
- Only if you intend to build Django
-
DO NOT install the Python workload into the Visual Studio version you are going to be building PTVS with.
- You CAN install the Python workload into other Visual Studio versions.
- Install the following individual components (see https://aka.ms/Ofhn4c for more info):
- MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (Latest)
- C++ ATL for latest v143 build tools with Spectre Mitigations (x86 & x64)
- C++ MFC for latest v143 build tools with Spectre Mitigations (x86 & x64)
- Install the following workloads:
- Install Visual Studio Dev18 Preview Community edition or higher
- Install the following workloads:
- .NET desktop development
- Desktop development with C++
- Visual Studio extension development
- ASP.NET and web development
- Only if you intend to build Django
-
DO NOT install the Python workload into the Visual Studio version you are going to be building PTVS with.
- You CAN install the Python workload into other Visual Studio versions.
- Install the following individual components:
- MSVC v145 build tools
- C++ ATL for latest v145 build tools with Spectre Mitigations (x86 & x64)
- C++ MFC for latest v145 build tools with Spectre Mitigations (x86 & x64)
- Install the following workloads:
-
Open a Visual Studio command prompt as Administrator, change to the root of where you cloned the PTVS repo, and run
.\Python\Prerequisites\deploy_test_targets.cmd -
Right-click on
<repopath>\Python\Prerequisites\EnableSkipVerification.reg(or …X86.reg on 32-bit OS) and click on merge- This disables strong name verification for the built binaries.
- If you've already run
\\vspreinstall\preinstall\preinstall.cmd, you can skip the registry script - If you get exception on missing target, either you forgot to run
deploy_test_targets.cmdor VS install dir in thedeploy_test_targets.cmdis incorrect. Fix the location and try again.
-
Install nodejs/npm from https://nodejs.org/en/download/
-
MICROSOFT EMPLOYEES ONLY - Install the azure artifacts credential provider.
- To do this, open a new powershell prompt and run the following:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx" - If this doesn't work, you can download the ps1 file and run it manually. See https://github.com/microsoft/artifacts-credprovider for more info.
- To do this, open a new powershell prompt and run the following:
-
MICROSOFT EMPLOYEES ONLY - Install the
vsts-npm-authpackage through npm. This will allow the script to download pylance from the azure artifacts feed as part of the next step. You will need to run the second command as an administrator, and it needs to be run from the root of the cloned repository. You may need to temporarily change the execution policy for Powershell as described in the next step:npm install -g vsts-npm-authvsts-npm-auth -config .npmrc -force
-
Restore npm and nuget packages by running
powershell .\Build\PreBuild.ps1- If you get an error about not being allowed to run scripts, you may need to change the execution policy on your machine. From a PowerShell run as administrator, you can use
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachineto allow local script execution. Once done you should probably go back to prior restrictions (typically done withSet-ExecutionPolicy -ExecutionPolicy AllSigned -Scope LocalMachine). - If you get
401 unauthorizederrors...- If you ARE a Microsoft Employee, you need to authenticate. To do this, run
.\Build\PreBuild.ps1 -interactive. After you login, a personal access token will be created for you. You won't need to do this again until the token expires. You will get an e-mail about the token, and you can browse to it and extend the expiration date by quite a while. - If you are NOT a Microsoft Employee, this should never happen to you. If it does, please create an issue in the PTVS repo and our team will get it fixed.
- If you ARE a Microsoft Employee, you need to authenticate. To do this, run
- If you get an error about not being allowed to run scripts, you may need to change the execution policy on your machine. From a PowerShell run as administrator, you can use
-
BUILD WITH MSBUILD BEFORE BUILDING THROUGH VISUAL STUDIO (SEE BELOW)
Building from the command line does NOT install PTVS into the VS Experimental hive (by default), nor create an installer, nor affect your main VS installation.
(The Exp hive is an isolated VS environment which allows you to install things without affecting your main VS install. It exists so you can work in parallel with your main install and you can blow it away if you break something.)
- Note, you need to run the build and deploy from the command line step at least once for deployment to work in the IDE.
-
To build from the command line, run the following in your VS developer shell from your repo root folder:
msbuild Python\dirs.proj -
To build AND deploy to the Experimental hive, run the following based on your target version:
For Dev17 (Visual Studio 2022):
msbuild Python\dirs.proj /p:VSTarget=17.0 /p:DeployExtension=true /p:RegisterOutputPackage=trueFor Dev18 (Visual Studio 2026):
msbuild Python\dirs.proj /p:VSTarget=18.0 /p:DeployExtension=true /p:RegisterOutputPackage=true- If you get errors when deploying the
Python - C++ project debugging supportextension to the Exp hive, it's probably due to path length issues. Follow the steps at https://www.tenforums.com/tutorials/51704-enable-disable-win32-long-paths-windows-10-a.html#option1 to enable long paths and try again.
- If you get errors when deploying the
-
To launch the VS Experimental hive, open the Visual Studio Command Prompt and run the following:
devenv /rootSuffix Exp
PTVS is packaged into several VSIX packages that get installed into the Visual Studio Experimental (Exp) Hive when you build.
- Open
./Python/PythonTools.slnin Visual Studio and selectProduct\Coreas the Startup Project. - Push F5 to build and run
- This will launch the Exp instance of VS through the debugger, with all the Python extensions installed.
- This is indicated by
Expin the upper right corner of the VS window.
- This is indicated by
- If an error appears rather than a new instance of VS, ensure the Project|Debug settings are correctly starting your
devenv.exewith arguments/rootSuffix Exp(and optionally/log). - Sometimes the updated vsix packages don't get installed to the Exp hive. A rebuild will usually fix this.
- This will launch the Exp instance of VS through the debugger, with all the Python extensions installed.
- To debug, set breakpoints in the non-Exp instance of Visual Studio, and perform actions in the Exp instance.
Core projects are always required to be built, and you will receive build errors if you unload one by mistake. They are grouped under the CoreProduct solution folder. The PythonTools.sln solution file includes a solution platform called "Minimal" that may be selected within Visual Studio to only build these projects. This will give the fastest possible build times, while only providing core functionality.
Projects under the "Product" solution folder are optional and may be unloaded to reduce build time. Once they are built, you should Clean the solution before unloading them. Note that some of the tests require these projects.
Projects under the "Tests" solution folder are also optional, but as we expect tests to be added or fixed for contributions you will likely need to run some of them. We do not require 100% test pass rate to accept a pull request, as there are a number of tests that rely on precise system configuration or are known to be unreliable.
Sometimes the Exp hive can get corrupted, which leads to all sorts of problems. The safest way to clear it is to just delete it, since a new one will be created the next time you build and run.
- Browse to
%localappdata%\Microsoft\VisualStudio- For example,
C:\Users\<yourUserName>\AppData\Local\Microsoft\VisualStudio
- For example,
- Look for folders starting with your Visual Studio major version and ending in
Exp- For Dev17:
17.0_xxxxxxxxExp - For Dev18:
18.0_xxxxxxxxExp
- For Dev17:
- Delete all of the folders that match what you found from the previous step
PTVS contains a large number of automated tests, including a mix of UI-based tests (which will start another VS, take control of your mouse, etc.) and non-UI tests. Some of the UI-based tests may fail intermittently or interfere with each other, while some tests may make incorrect assumptions about your system configuration (such as the availability of certain versions of Python). It is best to select the tests you need from the Test Explorer window and supervise them as they run.
- Documentation on docs.microsoft.com
- PTVS Project
- Development topics
- Additional resources
- wfastcgi (on PyPI)
- Video index; note that some videos are outdated.