views:

2129

answers:

2

I've got several AssemblyInfo.cs files as part of many projects in a single solution that I'm building automatically as part of TeamCity.

To make the msbuild script more maintainable I'd like to be able to use the AssemblyInfo community task in conjunction with an ItemGroup e.g.

<ItemGroup>
     <AllAssemblyInfos Include="..\**\AssemblyInfo.cs" />
</ItemGroup>

<AssemblyInfo AssemblyTitle="" AssemblyProduct="$(Product)" AssemblyCompany="$(Company)" AssemblyCopyright="$(Copyright)" 
      ComVisible="false" CLSCompliant="false" CodeLanguage="CS" AssemblyDescription="$(Revision)$(BranchName)" 
      AssemblyVersion="$(FullVersion)" AssemblyFileVersion="$(FullVersion)" OutputFile="@(AllAssemblyInfos)" />

Which blatently doesn't work because OutputFile cannot be a referenced ItemGroup.

Anyone know how to make this work?

+11  A: 

We use "linked" files in project. Solution Explorer -> Add Existin Item -> .. select_file .. -> arrow_on_left_of_add_button -> Add As Link

Then the selected file ( AssemblyInfo.cs for now ) is not copied to the direcotry of project, bud is only linked from specified path.

TcKs
Thats an interesting idea I hadnt thought of! Might give that a go if I can't find a solution through MSBuild. It would be nice to find out how to enumerate an ItemGroup for other uses too.
Kieran Benton
I do this as well. You can also include an assembly specific .CS file that looks like your average assemblyinfo.cs file, but contains the assembly specific bits.
Will
I have always done this as well. It works great.
caryden
+5  A: 

Try changing the @ to a % as below

<ItemGroup>
 <AllAssemblyInfos Include="..\**\AssemblyInfo.cs" />
</ItemGroup>

<AssemblyInfo AssemblyTitle="" AssemblyProduct="$(Product)" AssemblyCompany="$(Company)" AssemblyCopyright="$(Copyright)" 
                              ComVisible="false" CLSCompliant="false" CodeLanguage="CS" AssemblyDescription="$(Revision)$(BranchName)" 
                              AssemblyVersion="$(FullVersion)" AssemblyFileVersion="$(FullVersion)" OutputFile="%(AllAssemblyInfos)" />

This creates a call for every entry in AllAssemblyInfos.

Have a look at this article too, should help.

http://blogs.msdn.com/aaronhallberg/archive/2006/09/05/msbuild-batching-generating-a-cross-product.aspx

evilhomer
Thats exactly what I was trying to achieve, thanks!
Kieran Benton
No problem, I used to do that with for each loops in NANT, it's a little different in MSBuild, but it is also in many ways more powerful. Keep up the good questions :-)
evilhomer