将构建的程序集(包括 PDB、.config 和 XML 注释文件)复制到构建后文件夹

发布于 2024-10-21 01:30:10 字数 215 浏览 6 评论 0原文

有没有一种通用方法可以获取构建后事件来将构建的程序集以及任何 .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).

Thanks,
Kieron

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

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

发布评论

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

评论(1

浅紫色的梦幻 2024-10-28 01:30:10

您可以设置通用的OutputPath来在一个临时目录中构建Sln中的所有项目,并将所需文件复制到最新的构建文件夹中。在复制操作中,您可以设置一个过滤器来复制名称中不带“test”的所有 dll。

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

存在更复杂、更灵活的解决方案。您可以使用 CustomAfterMicrosoftCommonTargets 设置构建过程的挂钩。例如,请参阅此帖子
示例目标文件可以如下所示:

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

在该目标文件中,您可以指定所需的任何操作。

您可以将其放置在此处“C:\Program Files\MSBuild\v4.0\Custom.After.Microsoft.Common.targets”或此处“C:\Program Files\MSBuild\4.0\Microsoft.Common.targets\ImportAfter\PublishToLatest” .目标”。

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

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

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.

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

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