1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コマンドプロンプト(コマンドライン)から Visual Studio でファイルを開く

Last updated at Posted at 2020-01-24

VS Code や vim 等、多くのエディタはコマンドラインからファイルを開くことが出来ますが、Visual Studio ではスクリプトを介してコマンドラインから開くことが出来ます。

openfile.vbs
On Error Resume Next

Set objDTE = GetObject(, "VisualStudio.DTE.15.0")
If Err.Number<> 0 Then
    Set objDTE = CreateObject("VisualStudio.DTE.15.0")
    Err.Clear
End If

Dim fileName
Dim lineNumber
fileName = Wscript.Arguments(0)
lineNumber = int(Wscript.Arguments(1))

objDTE.MainWindow.Activate
objDTE.MainWindow.Visible = True
objDTE.UserControl = True

objDTE.ItemOperations.OpenFile fileName
objDTE.ActiveDocument.Selection.MoveToLineAndOffset lineNumber, 1

このスクリプトを利用してコマンドプロンプトから開くことが出来ます。

cmd.exe /c /path/to/openfile.vbs FILEPATH LINENUMBER
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?