Discussion:
2010 Beta 2: Build VCConfiguration
(too old to reply)
bmelt
2010-01-12 22:42:03 UTC
Permalink
I use code like following and it works fine with VS 2005 and 2008:

foreach (Project prjo in GetApplicationObject().Solution.Projects)
{
VCProject prj = (VCProject)prjo.Object;
IVCCollection cfgs = (IVCCollection)prj.Configurations;
foreach (VCConfiguration c in cfgs)
{
c.Build();
}
}

With VS 2010 Beta 2, only first configuration get built, then

An unhandled exception of type 'System.InvalidOperationException' occurred
in SamplesTester.exe
Additional information: Cannot perform this operation while this is not the
active configuration in the project.

What should be changed to get it working with 2010?

Thanks!

-Boris
Hongye Sun [MSFT]
2010-01-13 08:32:27 UTC
Permalink
Hi Boris,

Thanks for reporting this issue.

VS 2010 has changed a lot in VC project system. This behavior is possible
one of those changes.

Visual Studio builds projects by solution configuration instead of
individual project configuration. From your code, it seems that you want to
build all configurations of the projects under solution. If it is true, can
you use the following code to achieve the similar purpose?

I use VB macro as sample:

Dim sb As SolutionBuild = DTE.Solution.SolutionBuild

For Each cfg As SolutionConfiguration In sb.SolutionConfigurations
cfg.Activate()
sb.Build(True)
Next

The code above will builds all the solution configurations of the solution.
In order to build individual project, the following code is also workable:c

Dim sb As SolutionBuild = DTE.Solution.SolutionBuild

For Each cfg As SolutionConfiguration In sb.SolutionConfigurations
sb.BuildProject(cfg.Name,
DTE.Solution.Projects.Item(1).UniqueName, True)
Next

Hope it helps.

Sincerely,
Hongye Sun (***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within?2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
bmelt
2010-01-13 22:10:01 UTC
Permalink
Hi Hongye Sun,
Thank you for explanation I have to activate solution configuration with VS
2010. Actually I have much more code around the snippet I showed, so it is
preferable for me to keep old code with some small changes. I could do it
adding code for activation correspondent configuration in solution before
c.Build():
foreach (SolutionConfiguration sc in
GetApplicationObject().DTE.Solution.SolutionBuild.SolutionConfigurations)
{
if (sc.Name == c.ConfigurationName)
{
foreach (SolutionContext context in sc.SolutionContexts)
{
if (context.PlatformName == platform)
sc.Activate();
}
}
}

Regards,
Boris
Post by Hongye Sun [MSFT]
Hi Boris,
Thanks for reporting this issue.
VS 2010 has changed a lot in VC project system. This behavior is possible
one of those changes.
Visual Studio builds projects by solution configuration instead of
individual project configuration. From your code, it seems that you want to
build all configurations of the projects under solution. If it is true, can
you use the following code to achieve the similar purpose?
Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
For Each cfg As SolutionConfiguration In sb.SolutionConfigurations
cfg.Activate()
sb.Build(True)
Next
The code above will builds all the solution configurations of the solution.
In order to build individual project, the following code is also workable:c
Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
For Each cfg As SolutionConfiguration In sb.SolutionConfigurations
sb.BuildProject(cfg.Name,
DTE.Solution.Projects.Item(1).UniqueName, True)
Next
Hope it helps.
Sincerely,
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within?2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
Loading...