Answered by:
Problem setting the current configuration/platform

Question
-
hi.
i have a vs (2013) package that contains a single command. The command is supposed to change the current solution configuration as well as the current startup project. (infact, the command toggle between two configuration/startup tuples.)
The code to the command looks like this:
private void ToggleDebugTesterCallback(object sender, EventArgs e)
{
var dte2 = (DTE2) Marshal.GetActiveObject("VisualStudio.DTE.12.0");SolutionConfiguration s = dte2.Solution.SolutionBuild.ActiveConfiguration;
if (s.Name == "Debug Tester")
{
var config = dte2.Solution.SolutionBuild.SolutionConfigurations.Item("Debug Native Tester");
if (config != null)
{
config.Activate();
dte2.Solution.Properties.Item("StartupProject").Value = "kernel.native.tester";
}
}
else
{
// activate the other config/startup tuple here
}
}And basically, that works. However, after the command has run, not only the current solution configuration has changed, that current SolutionPlatform has changed also. (i.e.: I have several platforms, "win32", "win64", "mixedPlatform"..., and before the command is run, "MixedPlatforms" is the "current" platform. After the command is run, "Win32" is the current platform. )
Also, after the command has run, the "run in debugger" command appears to have changed. Before the command is run, there is the "usual" green arrow and the label says "Start". After the command has run, the label says "Local Windows Debugger". (I assume this is a side-effect of the platform change, but wanted to provide that info incase it helps finding a solution...)
So the question is: How do I change the solution configuration without changing the solution platform ?
WM_THXADVANCE
-thomas woelfer
Thursday, February 6, 2014 4:53 PM
Answers
-
Hi,
First, fix this:
var dte2 = (DTE2) Marshal.GetActiveObject("VisualStudio.DTE.12.0") returns any instance of VS if you have more than one. Use this instead to get the DTE service of the running VS instance where your package is loaded:
var dte2 = (DTE2) base.GetService(typeof(EnvDTE.DTE))
For an intro to the convoluted model of configurations/platforms see my posts:
The convoluted build configuration automation model (EnvDTE/EnvDTE80)
http://msmvps.com/blogs/carlosq/archive/2008/08/29/the-convoluted-build-configuration-of-the-automation-model-envdte-envdte80.aspxThe diagram of the convoluted build configuration automation model (EnvDTE/EnvDTE80) (Part 2)
http://msmvps.com/blogs/carlosq/archive/2008/09/01/the-fiagram-of-convoluted-build-configuration-automation-model-envdte-envdte80.aspxSee also my articles "Articles about build configurations / platforms" on the following page:
http://www.mztools.com/resources_vsnet_addins.aspx
Specifically, see:
HOWTO: Get or set the active solution configuration/platform from a Visual Studio add-in
http://www.mztools.com/articles/2013/MZ2013007.aspxMZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
- Proposed as answer by Carlos J. Quintero Thursday, February 6, 2014 8:06 PM
- Marked as answer by thomas_woelfer Friday, February 7, 2014 1:19 PM
Thursday, February 6, 2014 8:05 PM
All replies
-
Hi,
First, fix this:
var dte2 = (DTE2) Marshal.GetActiveObject("VisualStudio.DTE.12.0") returns any instance of VS if you have more than one. Use this instead to get the DTE service of the running VS instance where your package is loaded:
var dte2 = (DTE2) base.GetService(typeof(EnvDTE.DTE))
For an intro to the convoluted model of configurations/platforms see my posts:
The convoluted build configuration automation model (EnvDTE/EnvDTE80)
http://msmvps.com/blogs/carlosq/archive/2008/08/29/the-convoluted-build-configuration-of-the-automation-model-envdte-envdte80.aspxThe diagram of the convoluted build configuration automation model (EnvDTE/EnvDTE80) (Part 2)
http://msmvps.com/blogs/carlosq/archive/2008/09/01/the-fiagram-of-convoluted-build-configuration-automation-model-envdte-envdte80.aspxSee also my articles "Articles about build configurations / platforms" on the following page:
http://www.mztools.com/resources_vsnet_addins.aspx
Specifically, see:
HOWTO: Get or set the active solution configuration/platform from a Visual Studio add-in
http://www.mztools.com/articles/2013/MZ2013007.aspxMZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
- Proposed as answer by Carlos J. Quintero Thursday, February 6, 2014 8:06 PM
- Marked as answer by thomas_woelfer Friday, February 7, 2014 1:19 PM
Thursday, February 6, 2014 8:05 PM -
Carlos,
thank you very much. That was extremely helpful.
WM_THX
-thomas woelferFriday, February 7, 2014 1:19 PM