MsBuild Copy output and remove part of path

馋奶兔 提交于 2019-12-11 07:36:15

问题


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:

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

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

Note the removal of "Release" folder

My code is below.

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

Code extract is as follows

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


回答1:


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.



来源:https://stackoverflow.com/questions/4154922/msbuild-copy-output-and-remove-part-of-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!