954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

link to code file

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?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
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.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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 ;

Attachments DaniWeb4.zip (48.65KB)
BlackSun
Light Poster
46 posts since Feb 2008
Reputation Points: 28
Solved Threads: 5
 

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..

zig007
Newbie Poster
4 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

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

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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..

zig007
Newbie Poster
4 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

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

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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

zig007
Newbie Poster
4 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

i couldnt find what you mentioned in VS 2005..

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

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.

Attachments add_as_link.jpg 7.23KB
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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...

zig007
Newbie Poster
4 posts since Mar 2009
Reputation Points: 10
Solved Threads: 1
 

For ####'s sake, pride is retarded.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 
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.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 
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?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 
For ####'s sake, pride is retarded.


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

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You