BUG: Serialization of Project type does not include ProjectConfigurationToBuild and ProjectSolut

I'm working on a system for build automation (CI) and I'm having some problems with the Project type and that it doesn't include ProjectConfigurationToBuild and ProjectSolutionToBuild values when being serialized.

Here are the declarations from the type definition (Microsoft.TeamFoundation.Build.Common.Project):

[XmlArrayItem("ConfigurationToBuild", IsNullable =false)]
publicProjectConfigurationToBuild[] ItemConfigGroup {get;set; }
[
XmlArrayItem("SolutionToBuild", IsNullable =false)]
publicProjectSolutionToBuild[] ItemGroup {get;set; }

The ItemConfigGroup property is null and ItemGroup becomes a empty (0) array.

Here are snippets from my .proj file:

<ItemGroup>
<SolutionToBuildInclude="$(SolutionRoot)\Test\Test.sln"
/>
<
SolutionToBuildInclude="$(SolutionRoot)\Test2\Test2.sln"
/>
</ItemGroup>

<ItemGroup>
<ConfigurationToBuildInclude="Release|Any CPU"
>
<
FlavorToBuild>Release</FlavorToBuild
>
<
PlatformToBuild>Any CPU</PlatformToBuild
>
</
ConfigurationToBuild
>
<
ConfigurationToBuildInclude="Debug|Any CPU"
>
<
FlavorToBuild>Debug</FlavorToBuild
>
<
PlatformToBuild>Any CPU</PlatformToBuild
>
</
ConfigurationToBuild
>
</
ItemGroup>

I tried to inherit the Project class but was unable to get it to successfully serialize when I did that. I was thinking I could manually parse the XML .proj file and populate those two properties, but it throws exception. Here is what I attempted with:

[Serializable]
[XmlRoot("Project")]
publicclassProjectEx :
Project

I would appreciate any help I can get, as I need the SolutionToBuild values to figure out which team build to trigger when the users checks in source code.

[5731 byte] By [Sondre] at [2008-2-7]
# 1

After some testing it is very clear what seems to be the problem here. I don't know if Microsoft changed this close to the RTM or not, but when the .proj file contains more than a single ItemGroup the serialization fails.

If I remove the testing and and configuration ItemGroup's the serialization of Project.ItemGroup property works just fine. The ConfigurationToBuild never works as the property name is "ItemConfigGroup" and there exists no such element in the XML .proj file. Is it possible somehow to add an XPath criteria to the [XmlArrayItem] attribute, or does anyone have suggestions on how to fix this problem?

[XmlArrayItem("ConfigurationToBuild", IsNullable = false)]
public ProjectConfigurationToBuild[] ItemConfigGroup { get; set; }
[
XmlArrayItem("SolutionToBuild", IsNullable = false)]
public ProjectSolutionToBuild[] ItemGroup { get; set; }

Sondre at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Build Automation...
# 2

Here is a temporary solution that I'm using until I get some more proper way of handling this. The logic should really be handled by the XML serialization and not this XML DOM handling I wrote:

(Am I allowed to ask for better and more proper way of pasting and formatting source code in this forum?)

private Project ReadBuildType(string filename)
{

Project
project = null;
using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{

// Deserialize the .proj file
project = (Project)(_serializer.Deserialize(stream));
}
using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{

// Load the project file into an XML DOM object
XmlDocument xml = new XmlDocument();
xml.Load(stream);

// Select all the SolutionToBuild elements from the project file.
XmlNodeList list = xml.DocumentElement.GetElementsByTagName("SolutionToBuild", Namespace.MSBUILD);

// Create a new array for the ItemGroup property.
project.ItemGroup = new ProjectSolutionToBuild[list.Count];
for (int i = 0; i < list.Count; i++)
{
// Populate the array with new objects.
project.ItemGroupIdea = new ProjectSolutionToBuild();
project.ItemGroupIdea.Include = listIdea.Attributes[
"Include"].InnerText;
}

// Select all the ConfigurationToBuild elements from the project file.
XmlNodeList listConfig = xml.DocumentElement.GetElementsByTagName("ConfigurationToBuild", Namespace.MSBUILD);

// Create a new array for the ItemConfigGroup property.
project.ItemConfigGroup = new ProjectConfigurationToBuild[listConfig.Count];
for (int i = 0; i < listConfig.Count; i++)
{
// Populate the array with new objects.
project.ItemConfigGroupIdea = new ProjectConfigurationToBuild();
project.ItemConfigGroupIdea.Include = listConfigIdea.Attributes[
"Include"].InnerText;
project.ItemConfigGroupIdea.FlavorToBuild = listConfigIdea[
"FlavorToBuild"].InnerText;
project.ItemConfigGroupIdea.PlatformToBuild = listConfigIdea[
"PlatformToBuild"].InnerText;
}
}
return project;
}

Sondre at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Team Foundation Server - Build Automation...

Visual Studio Team System

Site Classified