This morning I finally became fed up with manually copying the compiled assembly for one of my new plugins. Each time I make a change to the plugin, I need to move it to the plugin host’s project folder. Not a big deal, but unacceptable according to question #2 of the Joel Test
This is a quick fix using msbuild. First right click on the project in Visual Studio and select “Unload Project”. Once unloaded, right click it again and select “Edit Project.csproj”.
Scroll down to the bottom of the project file. You should see something like:
<!-- To modify your build process, add your task inside one of the targets below and
uncomment it. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
Uncomment the AfterBuild target and modify it to look like the following:
<Target Name="AfterBuild" >
<Copy SourceFiles="bin\FzySqrApp.dll" DestinationFolder="C:\some\special\path\"></Copy>
</Target>
Or, if you only want to have the copy executed for a specific build configuration (in this case BuildAndCopy) you can add a condition:
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'BuildAndCopy'">
<Copy SourceFiles="bin\FzySqrApp.dll" DestinationFolder="C:\some\special\path\"></Copy>
</Target>
But what if we are already using the AfterBuild target for something else? Well, it is quite easy to add a new target. Below, I have added the CopyFile target to my project file and set it to run for my BuildAndCopy configuration.
<Target Name="CopyFile" Condition="'$(Configuration)' == 'BuildAndCopy'">
<Copy SourceFiles="bin\FzySqrApp.dll" DestinationFolder="C:\some\special\path\"></Copy>
</Target>
By default, msbuild will not execute the new target. We can fix this by adding CopyFile to the DefaultTargets property in the
tag at the top of the file:
<Project ToolsVersion="4.0" DefaultTargets="Build;CopyFile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
After you have made your changes, right click on the Project name and select “Reload Project” and build away!*
*If you need to debug your msbuild configuration, you might find it helpful to increase MSBuild’s verbosity. Go to Tools->Options, Projects And Solutions->Build and Run to set this.