I have the following piece of code to replace all tokens in a given set of files:
(I’m using the msbuild extensions detokenise task).
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="MSBuild.ExtensionPack.FileSystem.Detokenise" AssemblyFile="Extensions/MSBuild.ExtensionPack.dll"/>
<PropertyGroup>
<someValueToReplace>New Value</someValueToReplace>
</PropertyGroup>
<ItemGroup>
<TextFiles Include="test1.txt"/>
<TextFiles Include="test2.txt"/>
</ItemGroup>
<Target Name="Build">
<Detokenise TaskAction="Detokenise" TextEncoding="ASCII" TargetFiles="@(TextFiles)"/>
</Target>
</Project>
Unfortunately I get the following error:
(I don’t get this error if only one item exist in the ItemGroup).
(Note that I don’t want to explicitly inject the tokens that I want replaced).
“C:\Users\v\Desktop\msbuildSample\detokenise.xml” (default target) (1) ->
(Build target) ->
C:\Users\v\Desktop\msbuildSample\detokenise.xml(10,3): error : Property not found: toReplace
C:\Users\v\Desktop\msbuildSample\detokenise.xml(10,3): error : ArgumentException: Review error log\r
C:\Users\v\Desktop\msbuildSample\detokenise.xml(10,3): error :
My mistake .. I thought it was a bug in msbuild .. actually the issue was exactly what the error message indicated — I was trying to replace a variable called toReplace — but it wasn’t defined.