我需要编写构建脚本。我正在使用MSBUILD,因为它与VS.net集成在一起。我正在尝试将一些文件从构建环境复制到部署文件夹。我正在使用MSBuild的复制任务。但是与其复制目录树,不如我期望的那样。它将所有内容复制到一个文件夹中。我将目录树中的所有文件重复到一个文件夹中。我需要它来将文件夹和目录树复制到目标文件夹中。有什么我想念的吗?
这是我的构建脚本的相关部分:
<PropertyGroup>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<Source>outputfolder</Source>
<DestEnv>x</DestEnv>
<DeployPath>\\networkpath\$(DestEnv)</DeployPath>
</PropertyGroup>
<ItemGroup>
<TargetDir Include="$(DeployPath)\**\*" Exclude="**\web.config"></TargetDir>
<SourceDir Include="$(Source)\**\*" />
</ItemGroup>
<Target Name="Clean" >
<!-- clean detail ... -->
</Target>
<Target Name="migrate" DependsOnTargets="Clean">
<Copy DestinationFolder="$(DeployPath)" SourceFiles="@(SourceDir)" />
</Target>
最佳答案
我们在调试有关复制的MSBuild问题时发现的只是一颗 gem :
http://blog.scrappydog.com/2008/06/subtle-msbuild-bug-feature.html
ItemGroups是在Targets之前解析的,因此在脚本中进一步引用ItemGroup时,将不会拾取任何创建新文件(例如,编译!)的Targets。
Eric Bowen还描述了此“功能”的变通方法,即 CreateItem 任务:
<Target Name="Copy" >
<CreateItem Include="..\Source\**\bin\**\*.exe"
Exclude="..\Source\**\bin\**\*.vshost.exe">
<Output TaskParameter="Include" ItemName="CompileOutput" />
</CreateItem>
<Copy SourceFiles="@(CompileOutput)"
DestinationFolder="$(OutputDirectory)"></Copy>
</Target>
给他许多荣誉!
关于.net - 为什么MSBuild无法像我期望的那样复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/267030/