I am not against accidentally repeating something when necessary, but in MSBuild I really don't know how to avoid repeating. He does not offer "functions" in the usual sense; the target can be called only once, even through CallTarget , and <Import> only works at the Project level.
Here is a specific example that I am trying to de-repeat:
<Target Name="Tgt1"> <PropertyGroup><Conf1>Twiddle</Conf1><Conf2>Thing</Conf2></PropertyGroup> <PropertyGroup><xxxxxxxxxxExePath>$(xxxxxxxBuildRoot)\$(Conf1)Console-xxxxxxxxed</xxxxxxxxorExePath></PropertyGroup> <MSBuild Projects="$(BuildSingleProj)" Targets="Build;Merge" Properties="Configuration=$(Conf1)$(Conf2);Platform=$(Platform);CompiledFileName=$(CompiledFileName);ProjectName=$(ProjectName);SolutionFile=$(SolutionFile);Root=$(Root);Caller=$(MSBuildProjectFullPath)"/> <MakeDir Directories="$(xxxxxxxxorExePath)" /> <WriteLinesToFile File="$(xxxxxxxxorExePath)\xxxxxxx.IsPortable.txt" /> <WriteLinesToFile File="$(xxxxxxxxorExePath)\xxxxxxx.Global.Settings.xml" Lines="@(xxxxxxxLicense)" Overwrite="true" /> <Exec Command='$(xxxxxxxxorExePath)\xxxxxxx.exe -a "$(xxxxxxxBuildRoot)\$(Conf1)$(Conf2)-Merged\xxxxxxx.exe" "$(xxxxxxxBuildRoot)\$(Conf1)$(Conf2)-xxxxxxxxed\xxxxxxx.exe"'/> </Target>
I have four such goals: Tgt1 , Tgt2 , Tgt3 , Tgt4 . only thing that differs from these four goals is the first line that defines Conf1 and Conf1 .
The only more or less effective idea of eliminating duplication that I know of is to move common code to a new target and invoke it using the MSBuild task. This, unfortunately, requires the loooooong property string to be passed manually, and this task uses several (I counted 11 properties and 1 group of elements).
An additional requirement is that I can invoke a script with an arbitrary subset of these goals, for example. \t:Tgt2,Tgt3 .
Is there any reasonable alternative to just copy / paste this piece of code - is this not about copying around huge property lists?
dry msbuild
Roman starkov
source share