如何使用每个用户的自定义设置部署桌面.Net应用程序 [英] How to deploy a desktop .Net application with custom settings per user

查看:161
本文介绍了如何使用每个用户的自定义设置部署桌面.Net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的问题,但是intergoogles并没有那么有用。



我有一个C#桌面应用程序。每个客户需要定制某些属性,例如每个客户的组织名称,否则这些属性将独立于应用程序的实际功能,因此不需要编译。



将这些数据从VS(2008)中拖出应用程序并将其部署到客户的桌面上是最好的/首选的方法是什么?



例如,假设我在两个独立的组织中有两个单独的用户,因此每个用户需要单独的一组设置。我为每个人创建一个新的app.config文件?为了适应新的app.config文件,我必须为每个用户重建安装项目?



谢谢

解决方案

应用程序设置子系统允许您在每个用户或每个应用程序的基础上创建强类型的设置。只需右键单击项目,选择属性,然后单击设置选项卡。






应用程序设置概述


应用程序设置通过为客户端
计算机提供一个简单的方式
存储应用程序范围和
用户范围设置来满足
需求。使用Visual Studio或
代码编辑器,通过指定
名称,数据类型和范围
(应用程序或用户)来定义给定属性的
的设置。您甚至可以将
将相关设置放入命名的
组中,以便于使用和可读性。
一旦定义,这些设置是
持续存储,并在运行时自动读回内存
。一个可插入的
架构使持久性
机制可以更改,但是通过
默认,本地文件系统是



应用程序设置由
保存,将数据作为XML持久化到不同的
配置(.config)文件,
对应于设置
是应用程序范围还是用户范围。
在大多数情况下,应用程序范围的
设置是只读的;因为他们
是程序信息,你将
通常不需要覆盖它们。
相比之下,即使您的应用程序在部分信任下运行
,用户范围设置可以在运行
时安全地读取和写入
。有关部分信任的更多
信息,请参阅
Windows窗体概述中的安全性。


添加设置时Visual Studio在设置类中创建一个强类型的属性。它还在应用程序配置文件中创建一个条目。对于应用程序设置,这是设置的实际值。如果你愿意,你可以在安装时改变它。对于用户设置,这是设置的默认值。用户可以在运行时更改值。然后,您可以调用Save方法来保存更改的值。用户设置的当前值存储在存储在正确的每个用户文件夹中的user.config文件中,基于用户是否在漫游,本地等。



与Windows窗体一起使用时非常好,因为窗体和控件的各种属性可以在设计时绑定到应用程序设置。这意味着当应用程序启动时,这些属性将从设置中获取它们的初始值。如果值在运行时更改,设置将更改。然后,您可以在应用程序退出之前保存更改的设置。然后,当应用程序重新启动时,它们将自动使用。这只需要很少的代码。



即使这些是为.NET 2.0中的Windows Forms创建的,我已经将它们与其他项目类型,特别是单元测试项目一起使用。当然,在这种情况下,您没有每个用户的设置。


This seems like a simple question but the intergoogles have not been kind.

I have a C# desktop application. There are certain properties that need to be customized per customer, such as each customer's organization's name, that are otherwise independent of the actual functionality of the application and therefore do not need to be compiled into it.

What is the best/preferred method to pull this data out of the application, manage it in VS (2008), and deploy it to customers' desktops?

For example, say I have two separate users in two separate organizations, so they each need a separate set of settings. Do I just create a new app.config file for each of them? Would I have to rebuild the setup project for each user in order to accommodate that new app.config file?

thank you

解决方案

The Application Settings subsystem allows you to create strongly-typed settings, on a per-user or per-application basis. Just right-click the project, choose Properties, and click on the Settings tab.


From Application Settings Overview:

Application settings addresses both needs by providing an easy way to store both application-scoped and user-scoped settings on the client computer. Using Visual Studio or a code editor, you define a setting for a given property by specifying its name, data type, and scope (application or user). You can even place related settings into named groups for easier use and readability. Once defined, these settings are persisted and read back into memory automatically at run time. A pluggable architecture enables the persistence mechanism to be changed, but by default, the local file system is used.

Application settings works by persisting data as XML to different configuration (.config) files, corresponding to whether the setting is application-scoped or user-scoped. In most cases, the application-scoped settings are read-only; because they are program information, you will typically not need to overwrite them. By contrast, user-scoped settings can be read and written safely at run time, even if your application runs under partial trust. For more information about partial trust, see Security in Windows Forms Overview.

When you add a setting, Visual Studio creates a strongly-typed property in the settings class. It also creates an entry in the application config file. For an Application setting, this is the actual value of the setting. You could change it at installation time, if you like. For a User setting, this is the default value of the setting. The user can change the value at runtime. You can then call the Save method to save the changed value. The current value of User settings is stored in a user.config file stored in the correct per-user folder, based on whether the user is roaming, local, etc.

It's really very nice when used with Windows Forms, since various properties of forms and controls can be bound to application settings at design time. This means that when the application starts, these properties will take their initial values from the settings. If the values change at runtime, the settings will change. You can then save the changed settings before the application exits. They will then automatically be used when the application starts again. This takes very little code.

Even though these were created for Windows Forms in .NET 2.0, I've used them with other project types, especially unit test projects. Of course, in that situation, you have no per-user settings.

这篇关于如何使用每个用户的自定义设置部署桌面.Net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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