Copy built assemblies (including PDB, .config and XML comment files) to folder post build

谁都会走 提交于 2019-11-29 12:29:59

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!