Acessing currently opened solution in a vsix project
Asked Answered
A

2

7

I want to access the path to currently open solution in Visual Studio from a vsix project. How can I get that?

This thread tells if a solution is open or not but gives nothing about the path of the opened solution

Archaic answered 8/7, 2015 at 12:6 Comment(0)
M
1

I use this:

    public string GetInitialFolder(DTE dte)
    {
        if (!dte.Solution.IsOpen)
            return null;
        return System.IO.Path.GetDirectoryName(dte.Solution.FullName);
    }

But expect it to error, sometimes it cannot return a path!

Megalomania answered 8/7, 2015 at 15:12 Comment(0)
Q
7

I would suggest to avoid EnvDTE as much as possible when developing packages and use native services whenever possible. In this case IVsSolution.GetSolutionInfo

Quadricycle answered 9/7, 2015 at 9:52 Comment(2)
Could elaborate a bit on why you suggest this ?Bobbybobbye
The automation model (EnvDTE) is a layer on top of native VS services. 1) There are project types (named unmodeled) that don't fully implement it (setup projects, some database projects). 2) The implementation has bugs (for example EnvDTE.Project.CodeModel and EnvDTE.ProjectItem.FileCodeModel using new C# and VB.NET features 3) New features of VS (such as Lightweight Solution Load, LSL of VS 2017) are not implemented in EnvDTE. 4) Some automation DLLs such as VsWebSite.Interop are no longer included in the core editor installation of VS 2017. I could go on, but EnvDTE is a second-class citizenQuadricycle
M
1

I use this:

    public string GetInitialFolder(DTE dte)
    {
        if (!dte.Solution.IsOpen)
            return null;
        return System.IO.Path.GetDirectoryName(dte.Solution.FullName);
    }

But expect it to error, sometimes it cannot return a path!

Megalomania answered 8/7, 2015 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.