if i have two projects in the a solution and i want to use exactly the same code file in this two projects, how do i create that file in one project and link to that file from the other?

Recommended Answers

All 22 Replies

I don't understand anything. do you need to merge the output of two projects to one file or what??

I don't understand anything. do you need to merge the output of two projects to one file or what??

i dont understand too, i start to add some more functionality to a solution composed of 20 projects, and i see that there are some files which has a shortcut symbol, and i have been told that those .cs files refering to some concrete files in other projects, instead of repeating the code in various projects they are linked as a shortcut.

ooooh I got you.... but if you've the same functionality it's logical to deploy them as executable (e.g .dll) and refer to them from the projects need to use this logic..

Example
You've 10 projects should use some mathematical operations I do, I should deploy my operations in dll and refer to it from the 10 projects to use it and access it like you access .net library.
NOT to add code files of my operations in the 10 projects and use them, simply keep constancy in your mind, for sure in some stage you'll forget to update all files with the same operations or someone from your team needs the executable and they don't have time to read and compile the logic or keep this operations up-to-date with yours.

but in our case it is not logical to create a dll for each individual .cs file, let say from the project A i need one class file, from project B i need another, i can not create thousands of dlls, do you know how to create links between files?

You can just create a folder under the solution (Right click on the solution node then create folder then drag drop items) but take care you just add a reference to files which is mainly located in projects that's mean, you can't add file to this folder from project1 and call its methods in project2.

can you create an example like this : add two windows application projects to one solution. and i just want to add one class file to windows project1 then link to it from windows project 2. i tried creating a folder under the solution, and if i drag a file from any of the projects it is linked to there, but if i drag from the folder under the solution to any of the projects, it is copied.

i think it`s better to divide ur programe.cs classes into more than DLL or u can alot of classes in one namspace ; but u can add project1 in solution and adding the project1 namespace in ur certain project the choose ur class ;

Hi,
I am having the exact same problem, I need to use the same source in multiple projects and don't feel like creating DLL:s and binaries for everything.
Obviously there must be a way to share source code in C#, that's one of the most basic functions of all programming languages.

Have this been resolved, please post how you did it to this thread..

unfortunately it is not resolved, i was going to ask it to my supervisor but i couldnt because of my pride..

Ok, I know what you mean.
However, in this case it seems that the "C# way" is to generate hundreds of DLL:s which, frankly, is a really bad idea. Haven't people heard the expression "dll hell" and all it's implications? Version tracking issues?
I have developed in a multitude of languages and environments and have never heard of anything like this.
So please swallow that pride and ask your boss. I am sure that he will appreciate that you finish your project more than he will be annoyed having to answer one more question..

Are you going to add to my reputation then :) ? ten times ?

I found it!

It is done when adding a file to a project in VS2008 by right-clicking the project - > add -> Existing item.
When you have selected the file you want, click the small down arrow on the "add"-button and select "add as link".
This way the file isn't added(copied) to the project folder, but only linked to.

//Nicklias

i couldnt find what you mentioned in VS 2005..

Right Click on Project->Add->Existing Item->Select the file then on Add button you'll find arrow press on it then Add as Link.

Ok..that's strange.
According to this link, it seems like it works the same way there?
I wish i'd have found that tip before...

For fuck's sake, pride is retarded.

Ok..that's strange.
According to this link, it seems like it works the same way there?
I wish i'd have found that tip before...

if your applications are of same type, i think it is still better for you to create a class library project and add a reference to it. In my case one of them is mobile application and the other is windows application so there is no possibility of creating a common class library.

Right Click on Project->Add->Existing Item->Select the file then on Add button you'll find arrow press on it then Add as Link.

i cant see it on visual studio 2005, is this screen shot from 2008?

For fuck's sake, pride is retarded.

i started to wonder your age.. how old are you?

commented: rambling offtopic like a wannabe -2

i started to wonder your age.. how old are you?

95 years old

commented: very beneficial +3

Yes, it's on 2008

i found it, it is on the attached image.
thanks for your posts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.