1
我正在編寫一個msbuild腳本來部署多個目標。我正試圖重用一些元素,並獲得意想不到的行爲。Msbuild ItemGroup意外地累積要複製的文件
當我運行此文件凸出:從來源1目錄
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="All" DependsOnTargets="DeployTarget1;DeployTarget2">
</Target>
<Target Name="DeployTarget1">
<PropertyGroup>
<RootDir>.\source1</RootDir>
</PropertyGroup>
<ItemGroup>
<DeployFiles Include="$(RootDir)\**\*.dll" Exclude="$(RootDir)\bin\C_*.xml" />
</ItemGroup>
<Copy SourceFiles="@(DeployFiles)" DestinationFiles="@(DeployFiles->'D:\deploytest\dest1\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="DeployTarget2">
<PropertyGroup>
<RootDir>.\source2</RootDir>
</PropertyGroup>
<ItemGroup>
<DeployFiles Include="$(RootDir)\**\*.dll" Exclude="$(RootDir)\bin\C_*.xml" />
</ItemGroup>
<Copy SourceFiles="@(DeployFiles)" DestinationFiles="@(DeployFiles->'D:\deploytest\dest2\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
</Project>
DeployTarget1將文件複製到遞歸作爲Dest1處我期待。
DeployTarget2副本都來源1 和源2到dest2,這不是我的預期。
D:\deploytest>msbuild /t:All test.proj
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18052]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 8/20/2013 2:37:17 PM.
Project "D:\deploytest\test.proj" on node 1 (All target(s)).
DeployTarget1:
Copying file from ".\source1\test1.dll" to "D:\deploytest\dest1\test1.dll".
copy /y ".\source1\test1.dll" "D:\deploytest\dest1\test1.dll"
DeployTarget2:
Copying file from ".\source1\test1.dll" to "D:\deploytest\dest2\test1.dll".
copy /y ".\source1\test1.dll" "D:\deploytest\dest2\test1.dll"
Copying file from ".\source2\test2.dll" to "D:\deploytest\dest2\test2.dll".
copy /y ".\source2\test2.dll" "D:\deploytest\dest2\test2.dll"
Done Building Project "D:\deploytest\test.proj" (All target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.06
有誰知道爲什麼會發生這種情況?
你能指點我關於這個「功能」的文檔嗎?
謝謝,我看到它在文檔中現在'項目 「file2.cs」 不更換的項目 「file1.cs」;相反,文件名稱將附加到編譯項目類型的值列表中。在構建的評估階段,您無法從項目類型中移除項目。[MSBuild Items](http://msdn.microsoft.com/zh-cn/library/ms171453.aspx) – garrmark