开发者

Visual Studio 2008 - Is it possible for two projects to share common classes?

In Visual Studio 2008 I know its possible to have one solut开发者_开发问答ion with two (or more) projects.

Is it possible OR How is it possible for the projects to share common class files?

For example -> Project 1 has a log file handling class. Can Project 2 reference it?

My hope is to increase code re-use and avoid two copies of the same thing that need to be maintained.

The target is Winforms C# (3.5)


Yes, one project can reference the other one. Simply choose Add reference > Projects and select the project to be referenced.


You may want to move non-application specific common functionality to a library that is on it's own development track and reference that from both.


Yes, this is definitely possible. You need to add a reference to Project 1 from Project 2 (right-click Project 2 in the Solution Explorer, choose "Add Reference...", and choose Project 1 under the "Projects" tab).

Don't forget that the code for Project 1 and Project 2 is likely to be in different namespaces. You'll need to add the appropriate using statement(s).


You don't actually want the class to be in two projects. You want it to be in project A, and then add a reference from project B to project A. This will allow you to use the class in both projects.


Yes, it's called "Adding a Reference."

http://msdn.microsoft.com/en-us/library/s5zwxxdw(v=VS.71).aspx


Right click on the project that you want to use the common classes nd select "Add Reference...". In the dalog that appears, choose the "Projects" tab and select the project that contains the common classes.


You can also compile your classes you wanna use an put the to the global assembly cache

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜