Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Visual Studio to copy files?

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

like image 818
George2 Avatar asked May 04 '09 13:05

George2


People also ask

How do I copy a file from one project to another in Visual Studio?

Click the arrow button to the right of the file and select Move or Copy file from the dropdown menu. When you choose Copy this file from the move or copy dropdown, you will then be able to select which project to copy it to. You can make a copy of the file in the existing project or in another project.

How do I make a copy of a file in C#?

Copy(String, String) is an inbuilt File class method that is used to copy the content of the existing source file content to another destination file which is created by this function. Syntax: public static void Copy (string sourceFileName, string destFileName);


2 Answers

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.

like image 132
kay.herzam Avatar answered Sep 18 '22 16:09

kay.herzam


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.

like image 27
Vilx- Avatar answered Sep 22 '22 16:09

Vilx-