整个解决方案的通用 Settings.settings 文件 [英] common Settings.settings file for entire solution

查看:33
本文介绍了整个解决方案的通用 Settings.settings 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让解决方案的所有项目都有共同的属性文件?

Is there a way to have common Properties file for all the projects of the solution?

我有一个控制台应用程序和一堆其他类库文件,我只想为它们创建一个设置文件.

I have a console application and bunch of other class librarry files and i want to have only one Settings file for them.

我不是在谈论 app.Config 文件.我说的是 Settings.settings 文件.

I am not talking about app.Config file. I am talking about Settings.settings file.

知道我该怎么做吗?

将配置设置存储在设置文件而不是 app.config 中也是一个好习惯吗?

Also is it a good practice to store configuration settings in the Settings file rather than app.config?

推荐答案

将要跨项目共享的文件放在解决方案文件夹中.然后,在每个项目中,选择 Add Existing Item ..

Place the file you want to share across projects in a Solution Folder. Then, in each project, choose to Add Existing Item ..

在添加现有项目"对话框中,选择通用文件.不要单击添加"按钮,而是单击添加"按钮右侧的下拉箭头,然后从下拉菜单中选择添加为链接".

In the Add Existing Item dialog, choose the common file. Instead of clicking the Add button, click the drop-down arrow on the right side of the Add button and choose Add As Link from the drop-down menu.

如果这是针对设置文件,则需要为该文件设置自定义工具属性:

If this is for a Settings file, you need to set the Custom Tool property for the file:

如果您的文件是 Settings.settings,您可以打开项目属性并转到设置"选项卡,Visual Studio 将自动为您设置此自定义工具属性.

If your file is Settings.settings you can open your project properties and go to the Settings tab and Visual Studio will set this Custom Tool property for you automatically.

设置自定义工具后,您将看到在设置文件下创建的 Designer.cs 文件.此 Designer.cs 文件包含生成的代码,可让您以编程方式访问您的设置.

Once the Custom Tool is set, you will see a Designer.cs file created underneath your settings file. This Designer.cs file contains generated code to make your settings accessible programatically.

如您所见,Designer.cs 文件也是一个链接文件,它的物理位置将与您的设置文件相同.

As you can see, the Designer.cs file is also a linked file, and it's physical location will be the same as your settings file.

这篇关于整个解决方案的通用 Settings.settings 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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