Using AssemblyInfo to automatically update multiple AssemblyInfo.cs files

纵然是瞬间 提交于 2019-12-18 12:30:20

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/116140/using-assemblyinfo-to-automatically-update-multiple-assemblyinfo-cs-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!