我有几个相关的 Windows 注册表项,我想将它们打包在 MSI 中,以便 1) 有一个卸载过程,以及 2) 这些注册表项已应用于给定计算机的事实由添加/删除程序条目记录.
问题是我可以让 Wix# 很好地做到这一点,但如果所有注册表项都在“Dir”块内,我只能让 MSI 构建,并且最终实际上创建了一个物理文件夹,我不这样做不想要,在目标系统上。
作为一种临时解决方法,我最终使用了 Dir 块,指定了一个虚拟的“Temp”文件夹。安装程序实际上确实创建了我不想要的文件夹;我想要的只是应用注册表项。
WiX 文档将其底层结构 TargetDir 描述为本质上告诉安装程序在目标系统上执行其操作。请参阅http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/write_a_registry_entry.html
在本机 WiX XML 示例中,似乎不会在目标系统上创建无关文件夹;只会应用所需的注册表项。我可以使用什么 Wix# 语法结构来应用注册表项,同时避免在目标系统上创建实际文件夹?
到目前为止,我看到的所有 Wix# 示例似乎都具有在目标系统上创建实际文件夹的副作用,无论您是否需要。
我知道我可以通过获取注册表项的 .reg 文件,用热量将它们收集到 .wxs 文件,然后用蜡烛和光将其构建到 msi 来做到这一点。我真的很想将它保留在 C#/Wix# 世界中。在我的组织中,C# 是一项广为人知的技能;WiX 少一些。(承认 Wix# 是建立在 WiX 功能之上的,对 WiX 和 Windows Installer 有一定程度的理解是必不可少的;这是一个舒适区的事情,能够使用 C# 而不是 XML,而不是完全合乎逻辑的事情。)目前,我们手动执行了很多此类注册表设置任务,没有任何痕迹,也没有简单、可靠的卸载。
/// <summary>
/// Configure the Event Log on a Windows (server) to have MyApplication Log settings and record an entry for it in Programs and Features.
/// Note that this program creates the Windows Installer MSI that accomplishes this.
/// This program creates a WiX XML file that is then compiled by the WiX Toolkit (Candle and Light) into the MSI file.
/// </summary>
internal class Script
{
public static void Main()
{
// Define a new Installer Project object
var project = new Project("SetupMyApplicationEventLog" ,
// Provide dummy "Temp" install directory to satisfy WiX# Syntactical requirement. There are no actual files being installed.
new Dir(@"Temp"),
/*
* Event Log Registration Entries, translated from .reg file
*/
// First, add the root level key of the tree of keys
//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log]
//"EventMessageFile"="C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll"
new RegValue(
RegistryHive.LocalMachine,
@"SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log",
"",
"") { AttributesDefinition = "Component:Win64=yes" },
//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\STV.DSD.HQSYS.SERVICE2]
//"EventMessageFile"="C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll"
new RegValue(
RegistryHive.LocalMachine,
@"SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\" + "STV.DSD.HQSYS.SERVICE2",
"EventMessageFile",
"C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll") { AttributesDefinition = "Component:Win64=yes" },
//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\STV.VFS.ONLINE]
//"EventMessageFile"="C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll"
new RegValue(
RegistryHive.LocalMachine,
@"SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\" + "STV.VFS.ONLINE",
"EventMessageFile",
"C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll") { AttributesDefinition = "Component:Win64=yes" } );
// Set the properties of the setup project
// Set UI to minimal; there are no choices to be made here.
project.UI = WUI.WixUI_ProgressOnly;
project.Manufacturer = "STV";
project.OutFileName = "SetupMyApplicationEventLog";
project.GUID = new Guid("037C625A-609C-4C2C-9689-62A075B88AD7");
// Assign version # to setup MSI property of type System.Version
project.Version = new Version(4, 0, 0, 0);
// Add the Win64 attribute to the package, to force a 64-bit MSI to be created
project.Package.AttributesDefinition = "Platform=x64";
// Trigger the MSI file build
Compiler.BuildMsi(project);
//// Also create the .wxs file so we can see what was sent to WiX to build the MSI
Compiler.BuildWxs(project);
Console.WriteLine("productVersion=" + project.Version);
Console.ReadLine();
}
}
}