Resumé

Transfer Files After Project Build in Visual Studio

Cristian Merighi () 0.00

How to use MSBuild to move files across projects while building.
This article is obsolete. Some functionalities might not work anymore. Comments are disabled.

A «quickie» about how to exploit Visual Studio (and in particular MSBuild) to transfer files after some project's build.

To do that, it's needed to edit the very raw content of our project schema file. How? I think most of you know how, consider this a pleonastic refreshing:

VS2010
  1. Right click on the project label in the solution explorer window (project containing the files to be moved).
  2. Select the item named Unload Project.
  3. Right click again on the project name (now labeled as unavailable).
  4. Select Edit [Nome_Progetto].[cs|vb]proj.

Now you're put in front of an XML document whose root is named Project (well, being more precise, its name's {http://schemas.microsoft.com/developer/msbuild/2003{Project}}).
Add to the root node the following markup block:

Markup
  1. <PropertyGroup>
  2.     <ScriptsDestinationDirectory>E:\Components\Pacem 5\Pacem.TestWebsite\Scripts</ScriptsDestinationDirectory>
  3.     <ScriptsSourceDirectory>Client</ScriptsSourceDirectory>
  4.   </PropertyGroup>
  5.   <Target Name="AfterBuild">
  6.     <CreateItem Include="$(ScriptsSourceDirectory)\**\*.*">
  7.       <Output TaskParameter="Include" ItemName="ScriptsFilesToCopy" />
  8.     </CreateItem>
  9.     <Copy SourceFiles="@(ScriptsFilesToCopy)" DestinationFiles="@(ScriptsFilesToCopy->'$(ScriptsDestinationDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
  10.   </Target>

What's notable in markup block:

  • PropertyGroup node, we define here the involved variables, in this specific case ScriptsDestinationDirectory (physical path to target folder) and ScriptsSourceDirectory (relative path to source folder, named "Client").
  • Target @Name="AfterBuild" node, we put here an Output Element whit relevant pointers to the specified variables.
  • Transfer execution is described by the Copy node.

Hope that was helpful...

Update

Task can be equally accomplished - via project's properties panel - using Post-build event command-line.

VS Project Properties

Command-line syntax follows (notice that only .js files are recursively filtered in the example):

xcopy "$(ProjectDir)\Client\*.js" "$(SolutionDir)\Pacem.TestWebsite\Scripts\" /s /i /y

Take care. Bye.

Feedbacks

  • Re: Transfer Files After Project Build in Visual Studio

    Alberto Dallagiacoma Monday, April 2, 2012 0.00

    Why don't you use a Post Build script? It's simpler... :-)

  • Re: Transfer Files After Project Build in Visual Studio

    Cristian Merighi Monday, April 2, 2012 0.00

    my first option, I'll update it by adding the cmd line version! :)

feedback
 

Syndicate

Author

Cristian Merighi facebook twitter google+ youtube

Latest articles

Top rated

Archive

Where am I?

Author

Cristian Merighi facebook twitter google+ youtube

I'm now reading

Feeds