The situation is this:
- I have multiple config files in one folder
- I have transformation files with the same name in a different folder
- I want to output the transformed files with the same name to a third folder after the build
I can easily solve this by manually adding the nodes for each file. However, I don't want to bother with that (as one of us in the team will always forget to edit the csproj file when he/she adds a new config).
This is what I have now:
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
<ItemGroup>
<PathToConfigs Include="Configurations\EnvironmentDependent" />
<FilesToTransform Include="*.config"/>
</ItemGroup>
<TransformXml
Source="%(PathToConfigs)\%(FilesToTransform)"
Destination="OutputConfigs\%(FilesToTransform)"
Transform="%(PathToConfigs)\TransformFiles\%(FilesToTransform)" />
I don't get the proper syntax here, so it is not suprising that I get the following error message:
"The item metadata %(PathToConfigs) is being referenced without an item name. Specify the item name by using %(itemname.PathToConfigs)".
Update
As of Nick's answer I came to this solution:
<TransformXml
Source="@(FilesToTransform -> '%(Identity)')"
Destination="@(FilesToTransform -> '%(OutputFile)')"
Transform="@(FilesToTransform -> '%(Transform)')" />
I verified the paths of files as shown in the <Message ... />
-s.
However, I get the following error:
"Could not open Source file: Could not find a part of the path 'C:\fakepath\Configurations\EnvironmentDependent\file1.config;Configurations\EnvironmentDependent\file2.config'."
(I have renamed part of the path to C:\fakepath; otherwise I did not change path after the semi-colon: the first path in the error message is absolute, the second one is relative. The output of the message shows the relative paths of the files).
What did go wrong?
Update 2
Source problem is fixed with Source="%FilesToTransform.Identity"
. I'm having the same issue with Transform.