【发布时间】:2010-12-30 10:28:19
【问题描述】:
我为在任何给定客户端站点上的 ClickOnce 部署编写了一个 GUI(称为 MyGUI)。该 GUI 使用 @Marc Gravell 描述的 here 方法安装和配置 Windows 服务 (MyService)。这是我的代码,从 MyGUI 内部运行,其中包含对 MyService 的引用:
using (var inst = new AssemblyInstaller(typeof(MyService.Program).Assembly, new string[] { })) {
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try {
if (uninstall) {
inst.Uninstall(state);
} else {
inst.Install(state);
inst.Commit(state);
}
} catch {
try {
inst.Rollback(state);
} catch { }
throw;
}
}
请注意第一行:我正在获取 MyService 的程序集并进行安装。现在,麻烦的是,我完成部署的方式,我有效地从 GUI 的应用程序文件夹中引用服务的 EXE 文件。所以现在服务启动并开始在 MyService.config 文件中查找内容,但找不到,因为它位于其他人的 app 文件夹中,只有 GUI 的 MyGUI.config 文件存在。
那么,如何让 MyService.config 对服务可用?
【问题讨论】:
标签: c# deployment windows-services installation