Drag and drop .cs files not using “Add As Link” in Visual Studio

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.

Answers


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.


Although this question has been answered, I thought I'd provide another way, because I found this question while figuring out if it was possible to add linked files in Visual Studio using drag-drop, rather than the cumbersome Add Items dialog box. And while the answer here wasn't what I was looking for, I found out myself:

Holding down CTRL+SHIFT down while drag-dropping, will create linked files. Additionally holding down only CTRL will create copies, but not remove the source file.


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.


Need Your Help

Why version of SBT is playing role in name of fully qualified dependency?

scala sbt

Why version of SBT is playing role in name of fully qualified dependency ?

jquery game of life detect neighbour cells

javascript jquery conways-game-of-life

I'm currently working on a little jquery project. I want to build Conway's game of life with javascript/jquery/html. But I can't figure out, how to detect if a cell has alive neighbours. But I know I

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.