It looks like you cannot reference Item metadata when creating an ItemGroup from the target.
Change script to:
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Run" ToolsVersion="12.0"> <ItemGroup> <MyFiles Include="test.proj" > <ReadOnly Condition='1 == $([MSBuild]::BitwiseAnd(1, $([System.IO.File]::GetAttributes("%(Identity)"))))'>True</ReadOnly> </MyFiles> </ItemGroup> <Target Name="Run" Outputs="%(MyFiles.Identity)"> <Message Text="%(MyFiles.Identity) Not ReadOnly" Condition="%(MyFiles.ReadOnly) != True"/> <Message Text="%(MyFiles.Identity) ReadOnly" Condition="%(MyFiles.ReadOnly) == True" /> </Target> </Project>
The following output will be made:
D:\temp\test>"C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild.exe" test1.msbuild /t:run Microsoft (R) Build Engine version 12.0.30723.0 [Microsoft .NET Framework, version 4.0.30319.18444] Copyright (C) Microsoft Corporation. All rights reserved. Build started 10/30/2014 4:31:35 PM. Project "D:\temp\test\test1.msbuild" on node 1 (run target(s)). Run: test.proj Not ReadOnly Done Building Project "D:\temp\test\test1.msbuild" (run target(s)). Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:00.17 D:\temp\test>
You can change your script to this if all of your elements are guaranteed to exist before the script runs. However, I suspect, since you are using it for a purpose that they do not use. In this case, you may need to complete the CreateItem task.
source share