views:

1251

answers:

4

Hello everyone,

I want to create a Visual Studio (I am using VSTS 2008) project which simply does file copy work, in more details, I will add some files to this project and this project copy files (included in this project) to some destination location when I build the project.

Any ideas how to do this in VSTS?

BTW: I heard using proj file could do such kinds of task, but I have not found any good simple to learn samples for beginner. :-)

thanks in advance, George

A: 

The C#/VB.NET project files are MSBuild scripts. MSBuild can do whatever you need...

Lucero
Thats true, but the question is how is the requirement in the question acheived?
AnthonyWJones
I know MSBuild. I want to find some ready to use/reference sample to do file copy. Any recommendations?
George2
Have a look at this file (MSI, but installs samples only) with MSBuild samples and word documentation for them: http://download.microsoft.com/download/d/4/0/d401e5cd-04c7-4b72-b644-a00ae3fd5681/msbuildqs.msi
Lucero
Installed and find a couple of good samples, but not find an ready to use file copy sample. Could you recommend me a sample to start quickly to solve my confusion? :-)
George2
Here's a simple sample:http://www.sedodream.com/PermaLink,guid,8f6bbb30-ec22-4fc6-90a1-c32715598d23.aspx
Lucero
+2  A: 

You can add a post build step in Visual Studio:

  • Open the project properties (this works in C# projects, I guess for VB.NET this applies as well).
  • Select the Build Events tab
  • There you can add the post build event commands, for example

    copy $(ProjectDir)\bin\* SOME_OTHER_FOLDER\*

The $(ProjectDir) is a macro, there are a few more available, they will be shown, when you edit a command.

Then, if you have a look at the according project file (XYZ.csproj or XYZ.vbproj), you can see a property group added at the bottom of the file, such as:

  <PropertyGroup>
      <PostBuildEvent>copy $(ProjectDir)\bin\* SOME_OTHER_FOLDER\*</PostBuildEvent>
  </PropertyGroup>

This is how you would do it when directly editing an MSBuild file. Note that you don't need to launch Visual Studio in order to build and have your files copied, you can just pass the project file to the msbuild.exe.

kay.herzam
I would use xcopy which is a little more fail-safe.
KJAWolf
A: 

As mentioned before, Visual Studio .xxproj files are actually MSBuild files. So you can do in them whatever MSBuild allows them to do. I've used them to customize my build process quite a bit. In your case, what you're looking for is the Copy Task. You can add it in the AfterBuild target.

Vilx-
This was my first thought as well, but he asked about doing it in VS(TS).
kay.herzam
Yes, so? Doesn't this do what he wanted? When the project is built, the files in it are copied to some location. There are even great many variables he can play with.
Vilx-
A: 

In Visual Studio 2010, you use Custom Build tools

For example, this rule copies "faq.txt" to the output directory.

<ItemGroup>
  <CustomBuild Include="faq.txt">
    <Message>Copying readme...</Message>
    <Command>copy %(Identity) $(OutDir)%(Identity)</Command>
    <Outputs>$(OutDir)%(Identity)</Outputs>
  </CustomBuild>
</ItemGroup>
bobobobo