views:

25

answers:

3

If I remember correctly, in past versions of Visual Studio (6, 2003, 2005), if you add an existing file to a project / solution, the file will be left where it is, rather than copied into the current solution. Regardless, this is what I need in VS2008.

For example, I have two projects that, for 3rd party DLL reasons, need to link to different DLLs, yet I want to keep the wrapper and my higher level API identical.

Let's say I start with ProjectA, and it has files wrapper.cs and api.cs. wrapper.cs links to c1.dll and c2.dll. Now for reasons out of my control, I now need a ProjectB that uses wrapper.cs and api.cs, but links to c3.dll and c4.dll.

Ideally, I'd just create ProjectB in VS2008 and then use "add existing item" to reference wrapper.cs and api.cs in the ProjectA folder. But when I do this, it performs a file copy, and now I would need to keep track of the changes between the source files and merge as necessary.

Possible solutions that I could really use advice on executing: 1. perhaps there is an SVN trick that I could employ to make this work? I couldn't think of one, but if I could make the files in the ProjectB project link to the ProjectA files, I would be happy. 2. find the right option in VS2008 that will act like "add file reference". I went through the project's context sensitive menus and didn't find anything that works.

+2  A: 

Have you tried the add as link option ? When you open the "add existing item menu ... " find your file, select it and pick the arrow next to "Add" button and choose "Add as a link".

anthares
talking about a lousy UI (IMO). Why the heck would they put that in a droplist with those three options? "Add" should be the default. "Show previous versions" doesn't even belong in that list. "Add as link" should have been a checkbox so it's clear. When "Add" is the first in the list, it's very easy to miss. MS, drop the droplist and just have a checkbox!!! Ok, rant over. :) **Thank you** for pointing that out to me! I think that is **exactly** what I was looking for, but for the past two years had never once noticed.
Dave
FYI -- works perfectly. I just did a test and it went without a hitch. :) Thanks again.
Dave
Nice to hear that ! :)
anthares
A: 

You can edit the .csproj file to refer to the original file, but I thought it did this anyway - look at it in notepad and you'll see plenty of ...... relative directory paths.

There is one SVN trick you can use, you can use externals to check out the original files, and you can get these to any directory you like, but it cannot checkout to a directory that contains existing files - it clears the contents first IIRC.

gbjbaanb
VS2008 does actually make a file copy. Just try "add existing" right now and you'll see that your project will now have a copy of the file you had specified. Thanks for the SVN tip -- I'll have to look into "externals". The reason why I figured this would be a problem was because of what you said -- you can't check out in a non-empty directory.
Dave
A: 

I don't have a direct answer to your question, but it really sounds like the correct solution in this case is to isolate the functionality of wrapper.cs and api.cs, provide functionality to dynamically load their dependencies, and to package these as a seperate class library that each project can consume.

Ryan Brunner