MSBuild 3.5 just made my day
While doing some troubleshooting on a project I needed to manually copy some debug assemblies around after every build. But there were a lot of them, and whenever I need to do something repeatedly I try automate it with a script of some sort...because I'm lazy of course. There are a lot of choices today for a little quick and dirty script like this, Batch files, VBScript, Powershell, NAnt, but I thought I'd give MSBuild a try because I figured it would be the least amount of hassle, since moving files around is one of it's main duties during a build. The script was simple to write, but I hit a snag...the destination files were read only, and the copy errored out. MSBuild 2.0's copy task doesn't have an option to overwrite read only files. But MSBuild 3.5 does, so I learned a couple of tricks.
1. Run MSBuild.exe from C:\Windows\Microsoft.NET\Framework\v3.5 (instead of C:\Windows\Microsoft.NET\Framework\v2.0.50727). I have an external tool macro set up in my text editor (Textpad) to run the script currently being edited with a shortcut key, so this was simple to re-point.
2. Tell MSBuild you are using 3.5 features by adding ToolsVersion="3.5" to the Project element.
<Project DefaultTargets="Copy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <ItemGroup> <Assembly Include="Project1\bin\Debug\Project1.*"/> <Assembly Include="Project2\bin\Debug\Project2.*"/> <!-- etc... --> </ItemGroup> <Target Name="Copy"> <Copy SourceFiles="@(Assembly)" DestinationFolder="Destination\bin" OverwriteReadOnlyFiles="True"/> </Target> </Project>