将常用文件添加到C#中的某些差异项目中 [英] add common files to some difference projects in C#

查看:74
本文介绍了将常用文件添加到C#中的某些差异项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个不同路径的项目。我想在两个项目中使用一些常见文件(.cs文件)。

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



如何从两个项目的路径(Common文件夹)中添加这些公共文件?

谢谢你的帮助。


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

推荐答案

参见 MSDN上的解决方案项目 [ ^ ]。

如果您不喜欢上述方法,那么还要看看这个Stack Overflow问题:在几个项目之间共享c#类源代码 [ ^ ]。


从形式上讲,解决方案2完全正确。同时,在整个项目中使用相同文件的整个想法在架构上是有问题的。考虑让一个程序集引用另一个程序集并以这种方式共享代码。永远不要两次编译同一个文件。



你可以随时避免它。将一个或多个程序集专用于某些实用程序方法(例如),并通过引用其他程序集来使用此程序集。更长的路往往真的更短。 :-)



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


我找到了解决办法:右键点击你的项目, 添加 - > 现有项目...,选择* .cs文件并单击添加按钮旁边的向下箭头,然后选择添加为链接。
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".


这篇关于将常用文件添加到C#中的某些差异项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆