Console commands in the project root


It would be useful to be able to run console commands in my project root. For example, if I was using Scrapy in PTVS, I'd be able to tell Visual Studio to run a specific file and pass in certain arguments to the command line. Eclipse and Pydev has something similar where I can setup build and debug configurations. In Pydev I can tell the debug or build to point to "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py" and that "crawl myspider -o myfile.csv -t csv" should be passed as arguments. It would be great if PTVS had this!


pminaev wrote Oct 2, 2013 at 9:59 PM

VS has the ability to register "external tools", which can be parametrized by various things including the root of current active project, or the path to current file open in the editor (full list here: http://msdn.microsoft.com/en-us/library/vstudio/ekbzk5f8.aspx). Tools -> External Tools is where you can manage them, and every added tool gets an entry directly under Tools.

If the tool in question is a console tool, you can additionally enable "Use Output Window" for it, which will capture all output in the VS Output window for inspection after the process has exited. This only works if the tool in question does not take any keyboard input. Alternatively, you can uncheck the "Close on exit" checkbox - with that, the tool will run in a separate console window, but after it has completed, VS will insert a "Press any key to continue" prompt at the end.

Additionally, once you've registered the tool that way, you can bind it to a shortcut key in Tools -> Options -> Environment -> Keyboard. The command name is Tools.ExternalCommand##.

pminaev wrote Oct 2, 2013 at 10:01 PM

In your StackOverflow question, I assumed that you wanted a full-fledged console that would let you run ad-hoc console commands in the project root at will, i.e. an actual embedded console window in VS. But it seems that your scenario is actually more narrow, and you just want to run some predefined commands. If I'm wrong here, can you please edit the text of the work item to reflect this? It would also be great if you can describe some scenarios where you would find the generic console useful.

dizzyguy wrote May 1 at 8:00 PM

PyCharm has a tool that enables developers to do things with manage.py, e.g. migrations, from within the IDE. It would be great if we could do the same thing from within Visual Studio and PTVS.


pminaev wrote May 1 at 9:18 PM

To some extent, the Django Shell (which can be opened through the project context menu in Solution Explorer - it's under "Django" in 2.0, or under "Python" in current 2.1 dev build) covers it - this doesn't let you run manage.py, but it gives you access to all the Django classes that are wrapped by manage.py commands.