将构建的程序集(包括 PDB、.config 和 XML 注释文件)复制到构建后的文件夹 [英] Copy built assemblies (including PDB, .config and XML comment files) to folder post build

查看:18
本文介绍了将构建的程序集(包括 PDB、.config 和 XML 注释文件)复制到构建后的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种通用的方法可以让我获得构建后事件来复制构建的程序集以及任何 .config 和任何 .xml 注释文件到文件夹(通常是解决方案相关),而无需编写构建后事件解决方案中的每个项目?

Is there a generic way I can get a post-build event to copy the built assembly, and any .config and any .xml comments files to a folder (usually solution relative) without having to write a post-build event on each project in a solution?

目标是拥有一个包含整个解决方案的最后一次成功构建的文件夹.

The goal is to have a folder that contains the last successful build of an entire solution.

在多个解决方案上使用相同的构建解决方案也很好,可能启用/禁用某些项目(所以不要复制单元测试等).

It would be nice to use the same build solution over multiple solutions too, possibly enabling/ disabling certain projects (so don't copy unit tests etc).

谢谢,
基隆

推荐答案

您可以设置common OutputPath 将Sln 中的所有项目构建在一个临时目录中,并将所需文件复制到最新的构建文件夹中.在复制操作中,您可以设置过滤器以复制名称中没有test"的所有 dll.

You can set common OutputPath to build all projects in Sln in one temp dir and copy required files to the latest build folder. In copy action you can set a filter to copy all dlls without "test" in its name.

msbuild.exe 1.sln /p:Configuration=Release;Platform=AnyCPU;OutputPath=..latest-temp

存在更复杂和更灵活的解决方案.您可以使用 CustomAfterMicrosoftCommonTargets 为构建过程设置挂钩.例如,请参阅此 post.示例目标文件可以是这样的:

There exists more complicated and more flexible solution. You can setup a hook for build process using CustomAfterMicrosoftCommonTargets. See this post for example. Sample targets file can be like that:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <BuildDependsOn>
       $(BuildDependsOn);
       PublishToLatest
     </BuildDependsOn>
   </PropertyGroup>

   <Target Name="PreparePublishingToLatest">
     <PropertyGroup>
       <TargetAssembly>$(TargetPath)</TargetAssembly>
       <TargetAssemblyPdb>$(TargetDir)$(TargetName).pdb</TargetAssemblyPdb>
       <TargetAssemblyXml>$(TargetDir)$(TargetName).xml</TargetAssemblyXml>
       <TargetAssemblyConfig>$(TargetDir)$(TargetName).config</TargetAssemblyConfig>
       <TargetAssemblyManifest>$(TargetDir)$(TargetName).manifest</TargetAssemblyManifest>
       <IsTestAssembly>$(TargetName.ToUpper().Contains("TEST"))</IsTestAssembly>
     </PropertyGroup>
     <ItemGroup>
       <PublishToLatestFiles Include="$(TargetAssembly)" Condition="Exists('$(TargetAssembly)')" />
       <PublishToLatestFiles Include="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" />
       <PublishToLatestFiles Include="$(TargetAssemblyXml)" Condition="Exists('$(TargetAssemblyXml)')" />
       <PublishToLatestFiles Include="$(TargetAssemblyConfig)" Condition="Exists('$(TargetAssemblyConfig)')" />
       <PublishToLatestFiles Include="$(TargetAssemblyManifest)" Condition="Exists('$(TargetAssemblyManifest)')" />
     </ItemGroup>   
   </Target>

   <Target Name="PublishToLatest" 
           Condition="Exists('$(LatestDir)') AND '$(IsTestAssembly)' == 'False' AND  '@(PublishToLatestFiles)' != ''" 
           DependsOnTargets="PreparePublishingToLatest">

     <Copy SourceFiles="@(PublishToLatestFiles)" DestinationFolder="$(LatestDir)" SkipUnchangedFiles="true" />
   </Target>
 </Project>

在该目标文件中,您可以指定任何您想要的操作.

In that targets file you can specify any actions you want.

您可以将其放置在C:Program FilesMSBuildv4.0Custom.After.Microsoft.Common.targets"或此处C:Program FilesMSBuild4.0Microsoft.Common.targetsImportAfterPublishToLatest.targets".

You can place it here "C:Program FilesMSBuildv4.0Custom.After.Microsoft.Common.targets" or here "C:Program FilesMSBuild4.0Microsoft.Common.targetsImportAfterPublishToLatest.targets".

第三个变体是添加到您想要发布导入自定义目标的每个项目.请参阅如何:在多个项目文件中使用相同的目标

And third variant is to add to every project you want to publish import of custom targets. See How to: Use the Same Target in Multiple Project Files

这篇关于将构建的程序集(包括 PDB、.config 和 XML 注释文件)复制到构建后的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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