MsBuild 复制输出并删除部分路径

发布于 2024-10-02 06:45:01 字数 2006 浏览 0 评论 0原文

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

WDP 输出文件夹是从 BuildFolder“Release”复制的。

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

这有效,但我想从输出中删除 $(Configuration) 值。

因此,所需的输出文件夹布局是:

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

注意删除“Release”文件夹

我的代码如下。

我该如何更改它以给出所需的输出:

代码摘录如下

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰◇生如夏花灿烂 2024-10-09 06:45:01

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

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

请参阅属性函数了解更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文