John Mott
John Mott

Reputation: 445

Can Compile item tags appear in multiple ItemGroup tags in a MSBuild project file?

I'm doing some research into how to modify a .csproj file dynamically.

The items of interest are plain .cs files, no dependencies or special build requirements. I looked into EnvDTE but it looks really straightforward to just modify the XML in the .csproj file.

I see that the Compile item appears in an <ItemGoup> tag.

My observation from looking at my own projects is that not all <Compile> tags are grouped in the same <ItemGroup> tag. There does not appear to be a pattern for why some items are in one group and some are in another group.

To be clear, I'm not talking about having the same file in different ItemGroups, I'm talking about having x1.cs in one ItemGroup and x2.cs in another.

Is there a pattern to why some Compile tags appear in one ItemGroup and others appear in a different ItemGroup, or is it random?

If there is not a pattern I could simply add new Compile items into a new ItemGroup.

thanks,

john

Upvotes: 0

Views: 288

Answers (1)

Rolo
Rolo

Reputation: 3413

Visual Studio doesn't apply any specific pattern to group items.

The only special case to take in count is when the ItemGroup declares a condition.

If you are writing your code generator you can group items depending on your needs (i.e. Conditional builds or simple readability).

This link will give you a good idea about this.

Upvotes: 2

Related Questions