Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i have 2 project in difference paths. i want to use some common files (.cs files) in both of projects.
D:\Tests\WindowsFormsApplication_1\WindowsFormsApplication_1
D:\Tests\WindowsFormsApplication_2\WindowsFormsApplication_2
D:\Tests\Common

How do i add this common files from one path("Common" folder) for both of projects?
thank you for help.
Posted

See Solution Items at MSDN[^].
If you don't like the above approach then have also a look at this Stack Overflow question: "Share c# class source code between several projects"[^].
 
Share this answer
 
Formally speaking, Solution 2 is perfectly correct. At the same time, the whole idea of using the same file across project is questionable, architecturally. Think about having one assembly referencing another one and sharing code in this way. It's not good to compile the same file twice, ever.

You can always avoid it. Dedicate one or more assemblies to some utility methods (for example) and use this assembly by other assemblies by referencing it. Longer way is often really shorter. :-)

—SA
 
Share this answer
 
i found the solution: Right Click on your project, "Add" -> "Existing Item...", select your *.cs file and click on Down arrow next to the "Add" button and select "Add As Link".
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Sep-14 10:51am    
This is a perfectly correct solution. At the same time, the whole idea of using the same file across project is questionable, architecturally. Think about having one assembly referencing another one and sharing code in this way. It's not good to compile the same file twice, ever.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900