0

Firstly I am able to open a particular file programmatically in Visual Studio editor, with the help of How to programmatically open project/solution in already running Visual Studio?.

  var dte = Package.GetGlobalService(typeof(_DTE)) as DTE2;
  dte.ExecuteCommand("File.OpenFile","Program.cs");

After opening the file, I need to go directly to the line where the function definition starts(function name will be provided before opening the file) programmatically.

Does anyone knows how to go about this?

Siddhi Kamat
  • 135
  • 2
  • 11
  • Does this answer your question? [How can I perform "Go To Definition" programmatically in Visual Studio?](https://stackoverflow.com/questions/22344868/how-can-i-perform-go-to-definition-programmatically-in-visual-studio) – Sinatr Aug 09 '21 at 06:25
  • If you can work with the [ActiveDocument](https://learn.microsoft.com/en-us/dotnet/api/envdte80.dte2.activedocument) or [ActiveWindow](https://learn.microsoft.com/en-us/dotnet/api/envdte80.dte2.activewindow), you could use the [Find Interface](https://learn.microsoft.com/en-us/dotnet/api/envdte.find) (from `Document.DTE`) to locate text in the current Document. Configure the Find object (`Action`, `Target`, `FindWhat`) and execute it. – Jimi Aug 09 '21 at 06:40

0 Answers0