Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically getting the current Visual Studio IDE solution directory from addins
    primarykey
    data
    text
    <p>I have some tools that perform updates on .NET solutions, but they need to know the directory where the solution is located.</p> <p>I added these tools as External Tools, where they appear in the IDE Tools menu, and supplying <code>$(SolutionDir)</code> as an argument. This works fine.</p> <p>However, I want these tools to be easier to access in the IDE for the user through a custom top level menu (for which I created a Visual Studio integration package project) and through a context menu on solution nodes (for which I created a Visual Studio add-in project). I'm looking for a way to get the current solution directory through these contexts.</p> <p>I tried getting the solution information from the <code>VisualStudio.DTE</code> object:</p> <pre><code>EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE"); string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName); </code></pre> <p>But, this returns the solution directory for the add ins, not the current solution.</p> <p>I tried echoing <code>$(SolutionDir)</code> and reading it back:</p> <pre><code>System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "echo $(SolutionDir)"); // The following commands are needed to redirect the standard output. // This means that it will be redirected to the Process.StandardOutput StreamReader. procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; // Do not create the black window. procStartInfo.CreateNoWindow = true; // Now we create a process, assign its ProcessStartInfo and start it System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start(); // Get the output into a string string result = proc.StandardOutput.ReadToEnd(); </code></pre> <p>But, this returned the directory for the IDE, not the current solution.</p> <p>I didn't see any relevant information in the solution node <code>CommandBar</code>.</p> <p>Alternatively, if there was a way to programmatically access the defined Visual Studio external tools and launch them (using the already defined macro arguments), that would work.</p> <p>What is the solution?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload