I created a tool window as part of VSIX project and installed an extension to test it. So, the tool window need access to the current solution/project opened in visual studio. When the user created the project for the first time, We can fetch the path using DTE object as mentioned in below and I tried them and it works fine,
How can an add-in detect when a solution is loaded?
Acessing currently opened solution in a vsix project
But How to fetch the current solution path next time,when user just double clicks on solution? Right now when user opens the .sln file , the tool window breaks as it couldn't locate the opened solution path.
When the user double-clicks and open the solution we do not have a DTE
object in hand and we need a different way to get solutionInfo. I made it work using IVsSolution.GetSolutionInfo
IVsSolution solution = (IVsSolution) Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IVsSolution));
solution.GetSolutionInfo(out string solutionDirectory, out string solutionName, out string solutionDirectory2);
var solutionPath = solutionDirectory + System.IO.Path.GetFileNameWithoutExtension(solutionName);