6

Unfortunately, it is impossible to use the Windows command line to open a file in an already-running instance of Visual Studio at a specific line number. (VS 2008)

Open a file in Visual Studio at a specific line number shows a command-line parameter combination that fails, and presents code for an executable that can be called instead at the command line - but this code does not build out-of-the-box in VS 2008.

Does anyone know of a workaround (such as a VS macro) that is able to accomplish this very basic task?

Community
  • 1
  • 1
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
  • You will first have to specify which specific instance of VS should be selected. There are routinely more than one on my machine. – Hans Passant Jul 10 '10 at 14:09

3 Answers3

6

If you can upgrade to VS2008 SP1, then Fouré Olivier's answer should work to open a file in an existing instance of Visual Studio:

devenv /edit FILE_PATH

For other solutions similar to the answer you linked to, there's a similar perl script here and a python plugin here (see dte_put_file). Both are for use with vim, but you could fix them up to work for anything. (I haven't used either of them.)

Community
  • 1
  • 1
idbrii
  • 10,975
  • 5
  • 66
  • 107
  • Am I correct that your answer allows the file to be opened, but does not open it to a certain *line*? The latter is my question. – Dan Nissenbaum Oct 07 '11 at 22:50
  • You're correct. As far as I can tell, the command line options only open at a certain line if you're starting a new instance of Visual Studio. – idbrii Oct 12 '11 at 01:54
  • This answer works for me fine! This opens a file in existing VS window. – Sergey May 27 '13 at 12:37
4

The answer (months later): It cannot be done. (Not without writing a tedious script - and such a script cannot be straightforwardly, if at all, found on the internet.)

Therefore, it is true that Microsoft has simply not implemented this very basic feature into the IDE.

I do not know if this feature has been implemented in VS 2010.

The lack of this feature makes it impossible to conveniently use the IDE as an editor in conjunction with 3rd-party search tools (such as PowerGREP).

Sad.

Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
  • Very late to the party, just found this after searching Google for 'visual basic 2008 open file line by line' - Therefore for those people you can open a file in a textbox and use 'Textbox.Text.Split(Environment.NewLine)' to return an array of each line. – William Isted Sep 11 '12 at 15:56
  • some inspiration to write such a script can be found here: http://stackoverflow.com/questions/350323/open-a-file-in-visual-studio-at-a-specific-line-number – louisgab Feb 08 '13 at 16:07
2

Here is VBS script (Windows supports VBScript natively - no need for compilation or any additional interpreters)

open-in-msvs.vbs full-path-to-file line column

It opens full-path-to-file:line:column in running instance of MSVS or starts new one.

Evgeny Panasyuk
  • 9,076
  • 1
  • 33
  • 54