Soham Dasgupta
Soham Dasgupta

Reputation: 5199

Automatically move source code files to project folder in Visual Studio 2008/2010 which are added as link and residing outside the project folder

Is there a plugin/trick/macro for visual studio which automatically moves all files present outside a project directory and added as link, to the project directory and alters the location of the file in the project itself?

|--Project1
          |--File1.vb REM: already inside the project folder
|--File2.vb REM: outside the project folder and added as link to project1.

Is there any way to accomplish this?

|--Project1
          |--File1.vb REM: remains as it is
          |--File2.vb REM: now moved to project1 directory.

Upvotes: 4

Views: 715

Answers (2)

Doc Brown
Doc Brown

Reputation: 20044

It should not be too hard to write such a tool by yourself. The project files are just XML files, and references to source files look like this:

With links:

<ItemGroup>
  <Compile Include="..\Path_To_External_File\SourceFile.vb">
     <Link>SourceFile.vb</Link>
  </Compile>
</ItemGroup>

Same without links:

<ItemGroup>
    <Compile Include="SourceFile.vb" />
</ItemGroup>

So write a very simple program or script which reads all the project files to be processed, loop over all <Compile> items, make a copy of the source file or just move it to the desired location, and adapt the XML of the project file accordingly. If you have ever programmed some XML processing beforehand, using, for example, theXMLDocument class, then this should be implemented in a few hours (at maximum).

One final remark: you may (or may not) have to to deal with the case where the same files is referenced from different projects.

Upvotes: 3

Vivien Ruiz
Vivien Ruiz

Reputation: 626

Visual does the copy during compiling already if it's what you're looking for. On the other hand, if you want to really add the files, but not as a link, I pretty sure there is no native trick in VS for this.

Upvotes: 3

Related Questions