views:

423

answers:

3

Hello,

Is there a way to use add-as-link when dragging and dropping source files or entire source trees into a C# project?

Currently, dragging a tree of source files onto a C# project will cause Visual Studio to copy all files to mirror tree below my solution file.

This can be avoided with the the add-as-link option as depicted in the picture below. However, it gets tedious for large trees or when some files in a directory are already part of the project.

I've looked in Tools->Options, searched the web, and held various magic key combinations when dragging and dropping, to no avail.

I'm tempted to write a script that just globs my .cs files and runs a regular expression over my .csproj file. I'm aware of NAnt, Premake, and other solutions - but I'd like something lightweight.

Thanks,

Jaap Suter - http://jaapsuter.com

A: 

This is sort of a side comment, but if you do what I think you're asking, you'll have to be careful about the story around source control: I think that if the files don't exist in your workspace / mapped folder, you won't be able to store them in the structure that it will appear in your solution explorer pane...

+1  A: 

Probably not what you're asking for, but once I had two .NET applications which I wanted to share a lot of source files and so I placed both Visual Studio solutions in the same directory! It actually works, although I guess that a lot can be said about this approach...

Otherwise the most beautiful way to share code is by placing the shared code in a separate assembly, although this requires quite a bit of extra work if it is not written like that in the first place.

danbystrom
A: 

What you can also do if you don't find a solution is bind a directory to your project by hand once and let the project find all .cs files in that directory automatically when it loads.

This is easily done by changing your MSBuild file in the following way:

<ItemGroup>
  <Compile Include="SomeDirectory\**\*.cs"/>
</ItemGroup>

This will take all .cs files in SomeDirectory and include them to the project. This is very useful if there are often a lot of files added to the project. However, it may break on some machine adding useless files. That's why I would only recommend that on an external project that's not editable in your current workspace.

Coincoin