Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Wix#中,当仅部署注册表项时,如何避免在目标系统上创建物理文件夹?_C#_.net_Windows_Wix_Wixsharp - Fatal编程技术网

C# 在Wix#中,当仅部署注册表项时,如何避免在目标系统上创建物理文件夹?

C# 在Wix#中,当仅部署注册表项时,如何避免在目标系统上创建物理文件夹?,c#,.net,windows,wix,wixsharp,C#,.net,Windows,Wix,Wixsharp,我有几个相关的Windows注册表项,我想打包在MSI中,因此1)有一个卸载过程,2)这些注册表项已应用于给定计算机的事实由添加/删除程序项记录 问题是我可以让Wix#很好地完成这项工作,但我只能在所有注册表项都位于“Dir”块内的情况下让MSI进行构建,而这实际上会在目标系统上创建一个我不想要的物理文件夹 作为一种临时解决方法,我使用Dir块,指定一个虚拟的“Temp”文件夹。安装程序确实创建了我不想要的文件夹;我只想应用注册表项 WiX文档描述了它的底层构造TargetDir,本质上是告诉安

我有几个相关的Windows注册表项,我想打包在MSI中,因此1)有一个卸载过程,2)这些注册表项已应用于给定计算机的事实由添加/删除程序项记录

问题是我可以让Wix#很好地完成这项工作,但我只能在所有注册表项都位于“Dir”块内的情况下让MSI进行构建,而这实际上会在目标系统上创建一个我不想要的物理文件夹

作为一种临时解决方法,我使用Dir块,指定一个虚拟的“Temp”文件夹。安装程序确实创建了我不想要的文件夹;我只想应用注册表项

WiX文档描述了它的底层构造TargetDir,本质上是告诉安装程序在目标系统上执行它的操作。看

在本机wixxml示例中,似乎不会在目标系统上创建任何无关的文件夹;将仅应用所需的注册表项。我可以使用什么Wix#语法构造来应用注册表项,同时避免在目标系统上创建实际文件夹

到目前为止,我看到的所有Wix示例似乎都有这样一个副作用,即在目标系统上创建一个实际的文件夹,不管您是否需要

我知道我可以这样做:获取注册表项的.reg文件,通过加热将它们收集到.wxs文件中,然后通过蜡烛和灯光将其构建到msi中。我真的很想把这个留在C/Wix世界。在我的组织中,C#是一种众所周知的技能;不太可能。(承认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();
    }
}
<Directory Id="TARGETDIR" Name="SourceDir">
    <Component Id="ApplicationRegistry" Guid="YOUR-GUID-HERE">
         <RemoveFolder Id="RemoveTarget" Directory="TARGETDIR" On="both"/> 
         <RegistryKey Root="HKCU"
              Key="Software\Microsoft\[ProductName]"
              ForceDeleteOnUninstall="yes">
                <RegistryValue Type="integer" Name="SomeIntegerValue" Value="1" KeyPath="yes"/>
                <RegistryValue Type="string" Value="Default Value"/>
         </RegistryKey>
    </Component>
</Directory>
//
///将Windows(服务器)上的事件日志配置为具有MyApplication日志设置,并在程序和功能中为其记录一个条目。
///请注意,此程序将创建完成此操作的Windows Installer MSI。
///该程序创建一个WIXXML文件,然后由WIXToolkit(Candle and Light)编译到MSI文件中。
/// 
内部类脚本
{
公共静态void Main()
{
//定义新的安装程序项目对象
var project=新项目(“SetupMyApplicationEventLog”,
//提供虚拟“Temp”安装目录以满足WiX语法要求。没有实际安装的文件。
新董事(@“临时”),
/*
*事件日志注册条目,从.reg文件翻译而来
*/
//首先,添加键树的根级别键
//[HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log]
//“EventMessageFile”=“C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll”
新RegValue(
RegistryHive.LocalMachine,
@“系统\CurrentControlSet\Services\Eventlog\MyApplication Log”,
"",
“”){AttributesDefinition=“Component:Win64=yes”},
//[HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\STV.DSD.HQSYS.SERVICE2]
//“EventMessageFile”=“C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll”
新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\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\MyApplication Log\STV.VFS.ONLINE]
//“EventMessageFile”=“C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\EventLogMessages.dll”
新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”});
//设置安装项目的属性
//将UI设置为最小值;此处没有可供选择的选项。
project.UI=WUI.WixUI\u ProgressOnly;
project.Manufacturer=“STV”;
project.OutFileName=“SetupMyApplicationEventLog”;
project.GUID=新GUID(“037C625A-609C-4C2C-9689-62A075B88AD7”);
//将版本#分配给System.version类型的setup MSI属性
project.Version=新版本(4,0,0,0);
//将Win64属性添加到包中,以强制创建64位MSI
project.Package.AttributesDefinition=“平台=x64”;
//触发MSI文件生成
编译器.BuildMsi(项目);
////还要创建.wxs文件,以便我们可以查看发送到WiX的内容以构建MSI
编译器.BuildWxs(项目);
Console.WriteLine(“productVersion=“+project.Version”);
Console.ReadLine();
}
}

}

您可以通过将
标记添加到您不希望保留的目录中的组件来实现您想要的功能。看

生成的MSI将由
灯创建,并警告
LGHT1079
,您没有任何文件,但如果出于此目的,可以忽略

显示目录的简单示例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();
    }
}
<Directory Id="TARGETDIR" Name="SourceDir">
    <Component Id="ApplicationRegistry" Guid="YOUR-GUID-HERE">
         <RemoveFolder Id="RemoveTarget" Directory="TARGETDIR" On="both"/> 
         <RegistryKey Root="HKCU"
              Key="Software\Microsoft\[ProductName]"
              ForceDeleteOnUninstall="yes">
                <RegistryValue Type="integer" Name="SomeIntegerValue" Value="1" KeyPath="yes"/>
                <RegistryValue Type="string" Value="Default Value"/>
         </RegistryKey>
    </Component>
</Directory>