为什么MSBuild无法像我期望的那样复制 [英] Why doesn't MSBuild copy as I would expect

查看:85
本文介绍了为什么MSBuild无法像我期望的那样复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写构建脚本.我正在使用MSBUILD,因为它与VS.net集成在一起.我正在尝试将一些文件从构建环境复制到部署文件夹.我正在使用MSBuild的复制任务.但是与其复制目录树,不如我期望的那样.它将所有内容复制到一个文件夹中.我将目录树中的所有文件重复到一个文件夹中.我需要它来将文件夹和目录树复制到目标文件夹中.有什么我想念的吗?

I'm needing to script my build. I'm using MSBUILD because of it's integration with VS.net. I am trying to copy some files from the build environment to the deployment folder. I'm using the copy task of MSBuild. But instead of copying the directory tree as I would expect. it copies all the contents into a single folder. I repeat all the files from the directory tree end up in one folder. I need it to copy the tree of folders and directories into the destination folder. Is there something I'm missing?

这是我的构建脚本中最重要的部分:

Here is the relavant parts of my build script:

<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问题时发现了一个宝石:

Just a gem we found as we were debugging MSBuild issues around copying:

http://blog.scrappydog.com/2008/06/subtle-msbuild-bug-feature.html

ItemGroups是在Targets之前解析的,因此当沿着脚本进一步引用ItemGroup时,将不会拾取任何创建新文件(例如,编译!)的Targets.

ItemGroups are parsed before Targets, so any Targets that create new files (e.g. compiles!) won't be picked up when an ItemGroup is referenced further along the script.

Eric Bowen还介绍了此功能"的变通办法,即 CreateItem 任务:

Eric Bowen also describes a work-around for this "feature", the CreateItem task:

<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>

他很敬佩!

这篇关于为什么MSBuild无法像我期望的那样复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆