我要如何改变上安装.NET应用/用户设置? [英] How do I alter a .NET application/user settings on installation?

查看:184
本文介绍了我要如何改变上安装.NET应用/用户设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个Windows服务项目,用项目安装我试过如下:

In a Windows Service project, with a Project Installer I tried the following:

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
    }

    protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
    {
        base.OnBeforeInstall(savedState);
        Settings.Default.ASetting = "aValue";
        Settings.Default.Save();
    }

    protected override void OnAfterInstall(System.Collections.IDictionary savedState)
    {
        base.OnAfterInstall(savedState);
        Settings.Default.ASetting = "aValue";
        Settings.Default.Save();
    }
}

但是,当我检查config文件安装后,一个旧的价值依然存在。有中没有config文件通常[userfolder] \应用程序数据\本地

But after the installation when I check the .config file, a older value is still there. There was no .config file in the usual [userfolder]\AppData\Local

对于我来说是非常重要的变量定义在安装的时候,因为我会从安装项目的用户输入接收它的价值。这里的恒定值仅用于测试目的。

For me is important to define this variable in installation time since I will receive its value from a user input in the Setup Project. The constant value here is used for testing purposes only.

推荐答案

该框架将不会允许您更改在安装设置,因为是只读的应用程序设置,直到服务已安装并运行没有用户上下文(在用户名)。

The framework will not allow you to change the settings while installing, since Application settings are read-only and there is no user context until the service is installed and running (under a username).

我发现的唯一的解决办法是改变使用纯XML操作的配置文件的设置。我覆盖安装方法和更改文件本身。

The only solution I have found is to change the settings using plain XML manipulation of the config file. I override the Install method and make changes to the file itself.

这篇关于我要如何改变上安装.NET应用/用户设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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