简体   繁体   English

Visual Studio 2005/2008中的解决方案项目

[英]Solution Items in Visual Studio 2005/2008

Is it possible to add a class as a solution item and use it as a linked item in all the projects in the solution? 是否可以将类添加为解决方案项,并将其用作解决方案中所有项目中的链接项?

Basically I was thinking of creating a class (which will inherit ConfigurationSection ) and keeping it as the Solution Item. 基本上,我在考虑创建一个类(它将继承ConfigurationSection )并将其保留为解决方案项。 I wanted to add it as a linked item in all the projects in the solution, so that everyone can use it to access the configuration properties. 我想将其作为链接项添加到解决方案的所有项目中,以便每个人都可以使用它来访问配置属性。 (Refer to this tutorial for more details) (有关更多详细信息,请参阅本教程

Now the issue I am facing is that when I create a class in the solution item, it doesn't have any namespace. 现在我面临的问题是,当我在解决方案项中创建一个类时,它没有任何名称空间。 And it shows up in intellisense, inside the projects but once I create an object of the solution item class, the object doesn't show up in intellisense. 它显示在项目内部的智能感知中,但是一旦我创建了解决方案项目类的对象,该对象就不会显示在智能感知中。

Any ideas why? 有什么想法吗?

You would be better off putting your class into a library and then people can reference your library and use your class. 您最好将您的班级放入一个库中,然后人们可以引用您的库并使用您的班级。 If you use the linking methodology, you will run into problems when one project wants to reference another as you will have the same class in both projects in the same namepsace - it will not compile. 如果使用链接方法,则当一个项目要引用另一个项目时,您将遇到问题,因为您将在两个项目中使用相同的名称空间拥有相同的类-该项目将无法编译。

Update 更新资料

I can see from your other questions that you want to share configuration settings through a config file. 从您的其他问题中我可以看到您想通过配置文件共享配置设置。 Sharing the config file by linking is fine, it is just a plain text file so does not have any compilation issues. 通过链接共享配置文件很好,它只是纯文本文件,因此没有任何编译问题。 However, I would advise against sharing the class file using this method as discussed above. 但是,我建议不要使用如上所述的方法共享类文件。 Put your configuration class in a class library project which other people can reference as a project reference - they can then use your class. 将您的配置类放在一个类库项目中,其他人可以将其用作项目参考,然后他们便可以使用您的类。 Add the actual config file (with the settings) using linking. 使用链接添加实际的配置文件(带有设置)。 In this way your settings file will get copied across projects nicely, and people can use your configuration settings class by referencing it. 这样,您的设置文件将可以很好地跨项目复制,并且人们可以通过引用它来使用您的配置设置类。

Yes. 是。

Right-click each project, click Add, Add Existing File, navigate to the file, then click the down arrow next to the Add button and click Add As Link. 右键单击每个项目,依次单击“添加”,“添加现有文件”,导航到该文件,然后单击“添加”按钮旁边的向下箭头,然后单击“添加为链接”。

However, it would be better to put the class in a DLL project that is referenced by all of the projects. 但是,最好将类放在所有项目都引用的DLL项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM