Question

I have created an add-in that... among other things, adds a c++ project to a solution.

I have a problem with adding c++ projects to solutions that contain c# or vb.net projects (I'll refer to these solutions as dot net solutions).

I am sure you have all done this - without envdte automation.

Add a c++ project (with supported platforms Win32 and x64), to a dot net solution. Look at Configuration Manager -> since the dot net solution only has x86 and x64, the x64 configuration is correct, but in the x86 configuration you will see not Win32 for the c++ project - you will see x64 instead !!!!! Oh yeah, VS is smart enough to know that this is not going to work and does not select this configuration to build either !!!!

If you are doing this by hand, you as a developer should be smart enough to check, ok. But I am trying to build an automation to add this project - which means, the user might not be aware of this bug, will build the solution - and it will fail.

I have tried to change the platform - but it is read-only.

This is the only thing I have found so far:

SolutionConfiguration config = solution.SolutionBuild.SolutionConfigurations.Item("Debug");

string msg = "";

foreach (SolutionContext context in config.SolutionContexts)
{
  msg += context.ProjectName + context.ConfigurationName + context.PlatformName + context.ShouldBuild;
  context.ConfigurationName = "Debug";  // I can modify this but I don't want to
  if(context.PlatformName == "x64" && !context.ShouldBuild) // this must be the wrong platform
  {
    // I'd like to do that but it won't even compile
    context.PlatformName == "Win32";   // <--- intellisense says error
    context.ShouldBuild = true;        // compiles but checkbox doesn't get set
  }
}

I have considered trying to delete an entire configuration row and add a new one - but can't find how to do that...

I found "ConfigurationManager.DeleteConfigurationRow Method" but it only deletes a "Debug" or "Release" configuration... http://msdn.microsoft.com/en-us/library/ash2539k(v=vs.100).aspx

(I don't think that is what I want - I need to delete only the SPECIFIC configurations in relation to SPECIFIC platforms - or, since all platforms were added as x64, the ones that were marked as "ShouldBuild = False" or the project configurations corresponding to the x86 solution configuration. If I delete all configurations... that shouldn't work, and even then... what do I do next ?)

"ConfigurationManager.AddConfigurationRow Method" - there is nothing to specify platform... - so assuming I delete the row, how do I add it back correctly ?

Was it helpful?

Solution

For now, I am modifying the sln file -

It requires closing the solution, editing the text file, and re-opening it.

It is not ideal - if anyone can suggest a proper solution, I would appreciate it.

OTHER TIPS

There is a solution for this, but only for VS2012 and later. As of VS2012, you can now set the EnvDTE.SolutionContext.ConfigurationName property to the form "configuration|platform" to set both the target configuration and platform for a given project in the solution configuration.

I found the answer to this while searching for a solution for this problem myself. The original source that supplied this answer is at http://www.mztools.com/articles/2013/MZ2013014.aspx. You'll find a longer article and an example there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top