HOW-TO:DebugAndDevelopPythonScriptsWithVisualStudio

Getting Started
This guide is based on Visual Studio 2013, this guidance may be relevant for other versions but mileage may vary!


 * Install Visual Studio 2013 and update it.
 * Download Python for Windows ( <= v2.7)
 * Link to downloads at python.org
 * Install Python Tools for Visual Studio
 * Python Tools for Visual Studio on codeplex

Setting up your Project
If you have existing code go to File -> New -> Project and select From Existing Python Code, otherwise select Python Application. these project templates are under Templates / Python Update the name and the location relevant to your choice.

From Existing Python Code
For the existing code option ensure all the files are added, if you miss some you can add them to the project later. On the next page select the Python version you are running against. On the final page ensure you are happy with your project file name and location and click on Finish.

Python Application
TODO

Project Setup
These are optional but make the experience better.

To enable better intellisense for kodi components use XBMCstubs. This can be downloaded @ https://github.com/romanvm/xbmcstubs and all you need to do is add the location you downloaded the files from to the Search Paths. Add the kodi addons directory to the search paths for the addons you are referencing. An example would be \portable_data\addons\script.common.plugin.cache\lib to allow intellisense to work for StorageServer

Note: Intellisense will not be fully active until the DB is created, Press  to see its progress.

Running your project
Once you have a project up and running you have the magic of Visual Studio and the python tools at your disposal, along with any other adding to visual studio you like.

Right click on you python file that is the starting point for the plugin and ensure it is set as the startup file. If it is already bolded you do not have to worry about this.

Debugging your project
Work in Progress: Currently the attach process does not seem to be picking correctly for the breakpoints.

To debug your project you need to add a reference to ptvsd to your script and the project to enable intellisense.

pip install ptvsd import ptvsd ptvsd.enable_attach(secret = 'mysecret') ptvsd.wait_for_attach
 * Install ptvsd via pip
 * Add the following lines to the top of your script. Remember to comment out or remove once completed.
 * Set the breakpoint in your script that you want to check.
 * Start KODI
 * Start your plugin.
 * In Visual Studio use Debug -> Attach to Process menu command, which opens the Attach to Process dialog. The first thing to do in it is to open the Transport combo box, and change selection to Python remote debugging
 * For the qualifier add tcp://mysecret@localhost/