Copying a Solution Project's source files to another folder

I have a solution with several projects.

I want to copy the source files and project files to specific place.

I built the following msbuild file:

<Projectxmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ImportProject="$(TargetProject)" />

<TargetName="CopySourceCode">

<CopySourceFiles ="$(TargetProject)"DestinationFiles="$(SourceFolder)\$(TargetProject)"/>

<CopySourceFiles ="%(Compile.Identity)"DestinationFiles="$(SourceFolder)%(Compiler.RelativeDir)\%(Compile.Identity)"/>

</Target>

</Project>

I invoke it this way:

<
MSBuildProjects="copysources.proj"Targets="CopySourceCode" Properties="TargetProject=MyProject.csproj;SourceFolder=c:\sources\MyProject"/>

It works well for simple projects, I did not test it yet for complex ones. However, I feel I'm working too much ;).

First, I need to invoke it for every .csproj in my solution. Is there any way to automatically execute it for each project in the solution. Why isn't the solution itself a MSBuild file? If it were, that would be easy to do ...

Second, I actually prefer to have a Target in each .csproj file which is 'CopySourceCode'. To do that, if I'm right, I need to modify the standard .target files... Is this acceptable? I mean.. do you expect us to change those files? Is there any other way to add Targets to standard project types?

Third, is there a better way to do this?

Thanks a lot.

Andres

PS: Fourth... should I flag this post with 'This post contains a code sample' ;)?

[4328 byte] By [aaguiar] at [2008-2-7]
# 1
Hi aaguiar,
1) Yes solution files ought to be msbuild files. We'd like to fix that in a future version, but for now, we convert them into msbuild files on the fly when you ask msbuild.exe to build them. Here's a trick -- set an environment variable msbuildemitsolution=1. Then build the solution, and you'll see a *.sln.proj file which is the in-memory project we were using. Assuming your solution doesn't change (you don't add or remove any projects or configurations in it) you could use that file as if it were the solution in msbuild format. Because really it is.

2) It's best not to modify the *.targets files we ship, because if you do, you might break the build of all VS projects. Also, it would be hard for us to service and update those files later if we need to. We're going to try to make them read-only and add a comment encouraging people not to edit them directly.
To change the build for all projects on the machine, one thing you can do is look for "CustomBeforeMicrosoftCommonTargets" and "CustomAfterMicrosoftCommonTargets" in your microsoft.common.targets. These are imported automatically into there if they exist. I believe they are expected to be found at
<program files>\msbuild\v2.0\Custom.Before.Microsoft.Common.targets
<program files>\msbuild\v2.0\Custom.After.Microsoft.Common.targets

if you create a file there and put in what you need it should all just work.

Dan (msbuild@microsoft.com)

DanMoseley at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio MSBuild...

Visual Studio

Site Classified