Need help creating a file reference in a Visual Studio 2008 project
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.
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".
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.
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.
精彩评论