0

I would like to measure programmatically the solution load time in Visual Studio. I'm not sure whether is possible or not but I have the following code to try to achieve it:

// See https://aka.ms/new-console-template for more information
using System.Diagnostics;

var stopwatch = new Stopwatch();

stopwatch.Start();

var devEnvPath = @"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe";

var solutionPath = @"C:\git\my-project\my-project.sln";

var command = $"\"{solutionPath}\"";

var cmdsi = new ProcessStartInfo
{
    WindowStyle = ProcessWindowStyle.Normal,
    FileName = devEnvPath,
    RedirectStandardInput = true,
    UseShellExecute = false,
    Arguments = command
};

var cmd = Process.Start(cmdsi);

cmd.WaitForExit();

Console.WriteLine($"Took={stopwatch.ElapsedMilliseconds}ms");

The problem I have is that I previously tested fine with the /build flag and worked fine so I can measure the compile time but if I just want to measure the load time I'm not able to do it unless I manually close the Visual Studio instance that appears when the console app is running. Is there any switch or some handle I can use to try to hook into it and measure?

Carlos Torrecillas
  • 4,965
  • 7
  • 38
  • 69
  • You're not going to be able to "hook in" to anything using `Process.Start`, and the reason that `cmd.WaitForExit` call blocks until you actually close Visual Studio is that the command itself doesn't return until Visual Studio is closed. Is [this answer](https://stackoverflow.com/a/57917641/9796331) of any use to you? Looks like it deals with programmatically interacting with Visual Studio – madmonk46 Nov 04 '22 at 11:30
  • I think that's the way, but I'm getting NULL in the DTE object. I'm looking to see what I need for a .NET 6 console app – Carlos Torrecillas Nov 04 '22 at 12:25
  • Do you know if it is possible to use EnvDTE on a normal .NET Core 6 Console APP? Do you require a VSIX project? – Carlos Torrecillas Nov 04 '22 at 13:35

0 Answers0