1

我正在编写一个 msbuild 脚本来部署多个目标。我正在尝试重用一些元素并且得到了意想不到的行为。

当我运行这个项目文件时:

<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 按照我的预期将文件从 source1 目录递归复制到 dest1 。

DeployTarget2将source1和source2复制到 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

有谁知道为什么会这样?
你能指点我关于这个“功能”的文档吗?

4

1 回答 1

2

ItemGroups 是累积的。每次引用项目组时,都会将项目添加到现有组中。如果你想有明确的组,你要么需要给它们一个唯一的名字,要么你需要在使用前清除它们。

利用<DeployFiles Remove="**/*">

另请参阅:https ://stackoverflow.com/a/7915992/736079

于 2013-08-20T19:08:55.520 回答