【问题标题】:Execute a XCopy operation after all the projects build in MSBuild在 MSBuild 中构建所有项目后执行 XCopy 操作
【发布时间】:2020-11-03 04:12:53
【问题描述】:

我有一个 .proj 文件,该文件被配置为执行一个解决方案文件,该文件反过来构建解决方案中的所有项目。 我想添加一个 XCopy 操作,该操作应仅在所有项目构建完成后将所有项目的 .dll 文件复制到另一个位置。 我在下面尝试过,但它没有复制 dll。 我是编写 MSBuild 标签的新手,所以可能是我选择这种方法以这种方式编写任务是错误的。

如果有人知道,请提供解决方案。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition="'$(Configuration)' == 'Release|Debug'"/>
    <Platform Condition="'$(Platform)' == ''">x64</Platform>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <SolutionToBuild>
      <Properties>Configuration=$(Configuration);Platform=$(Platform)</Properties>
      <Targets>Clean;Build</Targets>
    </SolutionToBuild>
  </ItemDefinitionGroup>
  <ItemGroup>  
    <SolutionToBuild Include="..\Seg\Algorithms.sln" />
  </ItemGroup>

  <Target Name="Build"  >
      <MSBuild Projects="@(SolutionToBuild)" Targets="%(SolutionToBuild.Targets)" Properties="%(SolutionToBuild.Properties)" BuildInParallel="false" ContinueOnError="false" />
  </Target>
  <Target Name="Clean">
      <MSBuild Projects="@(SolutionToBuild)" Targets="Clean" Properties="%(SolutionToBuild.Properties)" BuildInParallel="false" ContinueOnError="false" />
  </Target>
  
  
  <PropertyGroup>
    <CopyDestination>..\Extern\Algo\bin\$(Configuration)\</CopyDestination>
    <CopySource>..\Seg\Algorithms\$(Configuration)\DoBin\</CopySource>
  </PropertyGroup>
  <ItemGroup>
    <FilesToCopy Include="$(CopySource)*.dll"/>
  </ItemGroup>
  <ItemGroup>
    <CustomBuildStep Include ="@(FilesToCopy)">
      <Message>Copying..</Message>
      <Command> XCOPY %(Identity)  $(CopyDestination) /f  /y </Command>     
    </CustomBuildStep>
  </ItemGroup>
  <PropertyGroup>
    <CustomBuildAfterTargets>Build</CustomBuildAfterTargets>
  </PropertyGroup>  
</Project>

【问题讨论】:

    标签: msbuild


    【解决方案1】:

    将目标视为被调用的方法。它们按顺序运行,因此您只需将副本放在解决方案构建之后:

    <Target Name="Build">
          <MSBuild Projects="@(SolutionToBuild)" Targets="%(SolutionToBuild.Targets)" Properties="%(SolutionToBuild.Properties)" BuildInParallel="false" ContinueOnError="false" />        
    
          <ItemGroup>
             <FilesToCopy Include="..\Seg\Algorithms\$(Configuration)\DoBin\*.dll" />
          </ItemGroup>
          <Copy SourceFiles="@(FilesToCopy)" DestinationFolder="..\Extern\Algo\bin\$(Configuration)\" SkipUnchangedFiles="true" />
    </Target>
    

    【讨论】:

    • 太棒了!!你拯救了我的一天......非常感谢 GazTheDestroyer ......我赞成你的回答。
    • 你也应该接受它,因为它解决了你的问题
    猜你喜欢
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多