copybuiltoutputofavisualstudioproject

Cancel Save Edit

How do I copy the final output assembly to a different location after the build for a VS project?


""To do this for a single project, add the PropertyGroup and Target below into your project file (.CSPROJ, VBPROJ, etc.):""

		 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	
...
<Import .../>
...

<PropertyGroup>
<PrepareForRunDependsOn>$(PrepareForRunDependsOn);MyCustomCopy</PrepareForRunDependsOn>
</PropertyGroup>

<Target Name="MyCustomCopy">
<Copy SourceFiles="$(TargetPath)"
DestinationFolder="c:\MyCustomDestinationFolder" />
</Target>
		 </Project>
	

""To do this for all VS projects on your machine, add the same PropertyGroup and Target to the end of your Microsoft.Common.targets file, which is located in your .NET Framework directory.""

""The way this snippet works is by overriding the PrepareForRunDependsOn property, which is originally defined in Microsoft.Common.targets. Here, we give it a new value, which is the old value concatenated with ";MyCustomCopy", effectively adding a new target name to the end of it. This property is in fact used to list the targets that the "PrepareForRun" target depends on (the PrepareForRun target is also defined in Microsoft.Common.targets). Thus we have inserted our own target ("MyCustomCopy") into the build process at the "PrepareForRun" stage, which is the stage responsible for copying built bits to their final locations (usually somewhere under the "bin" directory).""

""Then we actually define our own target called MyCustomCopy, and inside it is a call to a single task, the Copy task. $(TargetPath) is a property defined in (you guessed it) Microsoft.Common.targets, whose value is the full path to the final assembly.""