tags:

views:

169

answers:

1

Ok, I am not the best at MSBUILD. Actually, I don't know anything. I need some help configuring my solution file to tell MSbuild to copy the compiled output into a staging area. The solution has about 35 projects. All I need is around 5 of them the to be copied to the staging folder in release mode. Please assume I know nothing...

Thanks

+2  A: 

You could create a Target that looks like this:

  <Target Name="CopyFiles" DependsOnTargets="YourBuildTargets">
    <CreateItem Include="YourSolutionPath\bin\$(Configuration)\*.*">
      <Output ItemName="YourProjectOutputFiles" TaskParameter="Include"></Output>
    </CreateItem>

    <Copy SourceFiles="@(YourProjectOutputFiles)" DestinationFolder="$(DestinationFolder)"></Copy>
  </Target>

This will create a target called CopyFiles which depends on the completion of YourBuildTargets (You can put multiple dependencies in there, separated with semi colons). It describes an Item which includes all of the files (*.*) in the project directory. Then it runs the Copy command, and copies the files described by the item to the destination folder. If you have lots of projects all being build by 1 MSBuild script, you would have a CreateItem node for each project to index the files, and a corresponding Copy node to perform the copy.

Or if you just want to do this for each project separately, just put this block inside each .csproj file.

Now just include the CopyFiles target in the list of targets that gets build by your script.

Simon P Stevens
Does this go into the solution file?How do I set "YourProjectOutputFiles"?
Tim
No. The .csproj files are the MSBuild scripts. Put this in each of the .csproj files that you want the copy to run on.
Simon P Stevens
"YourProjectOutputFiles" is just the name of the output of the item, you don't need to change it.
Simon P Stevens
If you are just doing this by putting the code in each .csproj file, you should probably change the include property on the CreateItem node to just something like "$(TargetDir)\*.*", and you will need to change the DestinationFolder attribute on the Copy node to point to where ever you want the files to go.
Simon P Stevens
If you are using visual studio you could also do all of this just by right clicking and going to "Properties" on each project and going to the "Build Events" tab and adding a command to the "Post-build event command line". This just accepts standard commands, and if you hit the "Edit" button there are some simple macros you can insert to help you get the directories right. I didn't realise you were doing this from visual studio, I thought you wanted MSBuild scripts.
Simon P Stevens