2
我已經告訴下面應該創建元數據說他們是否只與否讀取文件的的ItemGroup:爲什麼%(Identity)擴展爲空字符串?
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Run"
ToolsVersion="12.0">
<Target Name="Main">
<ItemGroup>
<MyFiles Include="test.proj"> <!-- also tried with *.*. Using test.proj (this file) to be sure it is a file that exists -->
<ReadOnly Condition='1 == $([MSBuild]::BitwiseAnd(1, $([System.IO.File]::GetAttributes("%(Identity)"))))'>True</ReadOnly>
</MyFiles>
</ItemGroup>
</Target>
<Target Name="Run" Outputs="%(MyFiles.Identity)" DependsOnTargets="Main">
<Message Text="%(MyFiles.Identity) Not ReadOnly" Condition="%(MyFiles.ReadOnly) != True"/>
<Message Text="%(MyFiles.Identity) ReadOnly" Condition="%(MyFiles.ReadOnly) == True" />
</Target>
</Project>
但是,我得到下面的輸出(從開發者的命令提示符下運行時對於Visual Studio 2013):
S:\>msbuild test.proj
Microsoft (R) Build Engine version 12.0.30723.0
[Microsoft .NET Framework, version 4.0.30319.34014]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 30/10/2014 21:18:46.
Project "S:\test.proj" on node 1 (default targets).
S:\test.proj(9,13): error MSB4184: The expression "[System.IO.File]::GetAttributes('')" cannot be evaluated. The path is not of a legal form.
Done Building Project "S:\test.proj" (default targets) -- FAILED.
Build FAILED.
"S:\test.proj" (default target) (1) ->
(Main target) ->
S:\test.proj(9,13): error MSB4184: The expression "[System.IO.File]::GetAttributes('')" cannot be evaluated. The path is not of a legal form.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.01
S:\>
應該這樣工作嗎?如果是這樣,我哪裏錯了?