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

查看:248
本文介绍了将已生成的程序集(包括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).

谢谢,
Kieron

Thanks,
Kieron

推荐答案

您可以设置公共 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 为构建过程设置一个挂钩.例如,请参见此帖子. 样本目标文件可以像这样:

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 Files \ MSBuild \ v4.0 \ Custom.After.Microsoft.Common.targets"或此处:"C:\ Program Files \ MSBuild \ 4.0 \ Microsoft.Common.targets \ ImportAfter \ PublishToLatest.targets".

You can place it here "C:\Program Files\MSBuild\v4.0\Custom.After.Microsoft.Common.targets" or here "C:\Program Files\MSBuild\4.0\Microsoft.Common.targets\ImportAfter\PublishToLatest.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天全站免登陆