MsBuild复制输出并删除部分路径 [英] MsBuild Copy output and remove part of path

查看:110
本文介绍了MsBuild复制输出并删除部分路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MsBuild项目,该项目将构建各种解决方案,然后将Web部署项目的输出复制到具有两个子文件夹的目标文件夹中,如下所示:

I have an MsBuild project which builds various solutions and then copies the output of Web Deployment Projects into a destination folder with two sub folder as follows:

WDP输出文件夹是从BuildFolder发行版"中复制过来的.

The WDP output folders are copied over from the BuildFolder "Release".


DestFolder/PresentationTier/MyProject.xxx0Services_deploy/**Release**/Files...    
DestFolder/MidTier/MyProject.xx1UI_deploy/**Release**/Files...

这可行,但是我想从输出中删除$(Configuration)值.

This works but I want to remove the $(Configuration) value from the output.

因此所需的输出文件夹布局应为:

So the desired output folder layout is to be:


DestFolder/PresentationTier/MyProject.xxx0Services_deploy/Files...    
DestFolder/MidTier/MyProject.xx1UI_deploy/Files...

请注意删除"发布"文件夹

我的代码在下面.

如何更改此设置以给出期望的结果:

How can I change this to give the desired out please:

代码提取如下

  <Target Name="CopyMidTierBuildOutput" DependsOnTargets="CopyPresentationTierBuildOutput" >
<Message Text="Copying midTier Build Output=================" />

<CreateItem Include="$(DeploymentRoot)**/MyProject.xxx0Services_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/MyProject.xxx1Services.Host_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/MyProject.xxx2.Host.IIS.csproj_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/MyProject.xxx3Services_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx4_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx5Services.Host_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx6Services.Host_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx7Service.Host.IIS_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx8Services.Host_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx9Service.Host.IIS.csproj_deploy/$(Configuration)/**/*.*;
            $(DeploymentRoot)**/Nad.xxx10Services.Host_deploy/$(Configuration)/**/*.*">


  <Output TaskParameter="Include" ItemName="MidTierDeploys"/>

</CreateItem>


<Copy
    SourceFiles="@(MidTierDeploys)"
    DestinationFolder="$(DestFolder)/MidTier/%(RecursiveDir)" ContinueOnError="false"  />

推荐答案

您可以使用MSBuild 4的biltin功能实现预期的行为:

You can implement expected behaviour with biltin features of MSBuild 4:

  <ItemGroup>
    <DeploymentProjects Include="1_deploy" />
    <DeploymentProjects Include="2_deploy" />
  </ItemGroup>

 <Target Name="CopyMidTierBuildOutput" >
 <Message Text="Copying midTier Build Output" Importance="High"/>
  <ItemGroup>
    <MidTierDeploys Include="$(DeploymentRoot)**\%(DeploymentProjects.Identity)\$(Configuration)\**\*.*">
       <DeploymentProject>%(DeploymentProjects.Identity)</DeploymentProject>
    </MidTierDeploys>
  </ItemGroup>

  <Msbuild Targets="CopyDeploymentItem" 
           Projects="$(MSBuildProjectFile)" 
           Properties="ItemFullPath=%(MidTierDeploys.FullPath);ItemRecursiveDir=%(MidTierDeploys.RecursiveDir);ItemDeploymentProject=%(MidTierDeploys.DeploymentProject);Configuration=$(Configuration);DestFolder=$(DestFolder)"         /> 
</Target>

 <Target Name="CopyDeploymentItem" >
     <PropertyGroup>
         <ItemExcludePath>$(ItemDeploymentProject)\$(Configuration)</ItemExcludePath>
         <ItemDestRecursiveDirIndex>$(ItemRecursiveDir.IndexOf($(ItemExcludePath)))            </ItemDestRecursiveDirIndex>
         <ItemExcludePathLength>$(ItemExcludePath.Length)</ItemExcludePathLength>
         <ItemSkippingCount>$([MSBuild]::Add($(ItemDestRecursiveDirIndex),     $(ItemExcludePathLength)))</ItemSkippingCount>
         <ItemDestRecursiveDir>$(ItemRecursiveDir.Substring($(ItemSkippingCount)))</ItemDestRecursiveDir>
     </PropertyGroup>
    <Copy
        SourceFiles="$(ItemFullPath)"
        DestinationFolder="$(DestFolder)/MidTier/$(ItemDeploymentProject)/$(ItemDestRecursiveDir)"     ContinueOnError="false"  />
</Target>

有关更多信息,请参见属性函数.

See Property functions for more info.

这篇关于MsBuild复制输出并删除部分路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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