【发布时间】:2018-11-04 04:01:21
【问题描述】:
正如标题所示,我正在尝试将在我的主项目中创建的 user.config XML 文件扩展到我相邻的设置项目。我正在使用 Microsoft Visual Studio 2017 安装程序项目(link) 构建一个 MSI,并使用 Visual Studio 2017 创建一个简单的表单应用程序。
例如,这是我的两个项目-
在我的主要 Windows 窗体项目中,我有一个名为 testBool 的 bool 属性,默认设置为 false。
在我的表单中,我有一个按钮,它运行以下简单代码并将 testBool 的值设置为 true-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
namespace TestUserConfig
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("testBool = " + Properties.Settings.Default.testBool.ToString());
//setting the property to true
Properties.Settings.Default.testBool = true;
MessageBox.Show("Test Bool = " + Properties.Settings.Default.testBool.ToString());
//save the
Properties.Settings.Default.Save();
//location of the user.config file (reference to System.Configuration required)
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
MessageBox.Show(config.FilePath);
}
}
}
这一切都按预期工作,并将 user.config 文件输出到以下路径- C:\Users\USERNAME\AppData\Local\Microsoft_Corporation\PROJECTNAME_umi0kjiiephephcroktxjbzai0nh\14.0.7208.5000\user.config
我遇到的问题是,当我构建我的 MSI 时,相同的代码没有像我预期的那样运行。事实上,MessageBox.Show 甚至没有运行,除了最后一行代码——“MessageBox.Show("Hello!!");”
我希望剩余的消息框至少输出一个空白的消息框窗口。
此外,在 MSI 构建目录 (c:\Program Files (x86)\install dir) 我看到一个名为“PROJECTNAME.dll.config”的文件,其中包含 testBool 的默认值。
如果我发布一次单击应用程序,则该应用程序可以正常工作。
我需要在我的设置项目中添加一些东西来完成这项工作吗?
我已经阅读了所有能找到的关于这个问题的帖子,但似乎找不到合适的答案。我真的不想在学习 WIX 上投入大量时间,但如果这是唯一的途径,我可能需要这样做。
【问题讨论】:
标签: c# winforms visual-studio windows-installer settings