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.

Screenshot of the add-as-link functionality in Visual Studio http://jaapsuter.com/images/add_cs_file.jpg

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

How to retrieve the last message from Quickblox in iOS?

ios swift quickblox

I send message to the chat dialog but I am not able to retreive the last messages.

load scripts asynchronosly and have a fallback

javascript deferred-execution

My objective here is to load scripts asynchronously when the browser supports defer or async.