Wix Toolset-配置文件的最佳实践?

时间:2019-01-24 15:54:46

标签: c# wix

我有一个项目,必须先正确配置appsettings.json文件,然后才能运行它。

到目前为止,我已经搜索了一段时间,但是找不到解决方案。 我已经利用热量将所需的dll迁移到安装目录。 我本来要编辑此json文件:

  1. 创建了一个自定义操作,以将模型序列化到appsettings.json文件中,但是由于某种原因,该自定义操作导致了我无法调试的错误(Googled找到了3个不同的解决方案,但遗憾的是,没有一个解决方案能够帮助我)

  2. 我已决定在安装后打开json文件,该文件可以正常工作,但我无法找到一种方法来以管理员身份打开记事本来编辑json文件(我已经尝试了很多解决方案一个)

应采用哪种解决方案?也许我只是在搜索解决方案方面不擅长,但是也许对于哪种解决方案是最佳实践会有所帮助。

Product.wxs

<?xml version="1.0" encoding="UTF-8"?>
<!-- The name of the product -->
<?define Name = "xxx" ?>
<!-- The manufacturer, for setup package publisher and folder info -->
<?define Manufacturer = "xxx" ?>
<!-- The version number of this setup package-->
<?define Version = "1.0.0" ?>
<!-- UpgradeCode must be unique and not changed once the first version of the program is installed. -->
<?define UpgradeCode = "{145ED92C-BA1B-4257-8791-2337A012EEE7}" ?>
<?if $(var.Platform) = x64?>
<?define bitness = "(64 bit)"?>
<?define Win64 = "yes"?>
<?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?> 
<?else ?>
<?define bitness = "(32 bit)"?>
<?define Win64 = "no"?>
<?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="$(var.Name) $(var.bitness)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Version="$(var.Version)" Language="1033">
        <Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated"/>

        <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
        <Media Id="1" Cabinet="xxx.xxx.xxx.WindowsService.cab" EmbedCab="yes" />

        <Feature Id="MainApplication" Title="Main Application" Level="1">
            <ComponentRef Id="$(var.xxx.xxx.xxx.WindowsService.TargetFileName)" />
            <ComponentGroupRef Id="HeatGenerated"/>
        </Feature>

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="$(var.PlatformProgramFilesFolder)">
                <Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
                    <Directory Id="INSTALLFOLDER" Name="$(var.Name)" />
                </Directory>
            </Directory>
        </Directory>

        <DirectoryRef Id="INSTALLFOLDER">
            <Component Id="$(var.xxx.xxx.xxx.WindowsService.TargetFileName)" Win64="$(var.Win64)" Guid="FD94EF3C-4A0B-4102-AF1E-2A489B4DB7DF">
                <RemoveFile Id="ALLFILES" Name="*.*" On="both" />
                <ServiceInstall Id="ServiceInstaller"
                                Type="ownProcess"
                                Name="xxx.xxx.xxx.WindowsService"
                                Account="LocalSystem"
                                DisplayName="$(var.Name)"
                                Description="Deployment agent for xxx"
                                Start="auto"
                                Interactive="yes"
                                Vital="yes"
                                ErrorControl="critical"
                                Arguments="/start xxx.xxx.xxx.WindowsService"/>
            </Component>
        </DirectoryRef>
        <UIRef Id="SetupDialogUI" />

        <Binary Id="bgPic" SourceFile="images/bg.bmp"/>
        <Binary Id="cancelbtn" SourceFile="images/cancelbtn.bmp"/>
        <Property Id="Cancel">cancelbtn</Property>

        <InstallExecuteSequence>
            <Custom Action='xxx.xxx.xxx.WindowsService.CustomAction' After='InstallFinalize'>NOT Installed</Custom>
        </InstallExecuteSequence>
    </Product>
</Wix>

来自MSI的错误日志

MSI (c) (10:64) [15:11:16:149]: Note: 1: 1723 2: xxx.xxx.xxx.WindowsService.CustomAction 3: SaveAppsettings 4: C:\Users\vsun\AppData\Local\Temp\MSIFC10.tmp 
MSI (c) (10:64) [15:11:16:149]: Note: 1: 2205 2:  3: Error 
MSI (c) (10:64) [15:11:16:149]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1723 
MSI (c) (10:64) [15:11:16:149]: Note: 1: 2205 2:  3: Error 
MSI (c) (10:64) [15:11:16:149]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2867 
DEBUG: Error 2867:  The error dialog property is not set
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2867. The arguments are: , , 
MSI (c) (10:64) [15:11:16:154]: Font created.  Charset: Req=0, Ret=0, Font: Req=MS Shell Dlg, Ret=MS Shell Dlg

Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor.  Action xxx.xxx.xxx.WindowsService.CustomAction, entry: SaveAppsettings, library: C:\Users\vsun\AppData\Local\Temp\MSIFC10.tmp 
MSI (c) (10:64) [15:11:17:024]: Note: 1: 2205 2:  3: Error 
MSI (c) (10:64) [15:11:17:024]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709 
MSI (c) (10:64) [15:11:17:024]: Product: xxx xxx xxx (32 bit) -- Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor.  Action xxx.xxx.xxx.WindowsService.CustomAction, entry: SaveAppsettings, library: C:\Users\vsun\AppData\Local\Temp\MSIFC10.tmp 

Action ended 15:11:17: xxx.xxx.xxx.WindowsService.CustomAction. Return value 3.
MSI (c) (10:64) [15:11:17:025]: Note: 1: 2205 2:  3: Error 
MSI (c) (10:64) [15:11:17:025]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2896 
DEBUG: Error 2896:  Executing action xxx.xxx.xxx.WindowsService.CustomAction failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: xxx.xxx.xxx.WindowsService.CustomAction, , 

自定义操作

using System;
using System.Collections.Generic;
using System.Text;
using xxx.xxx.xxx.xxx.Models;
using Microsoft.Deployment.WindowsInstaller;
using Newtonsoft.Json;
using System.IO;

namespace xxx.xxx.xxx.WindowsService.CustomAction
{
    public class CustomAction
    {
        [CustomAction]
        public static ActionResult SaveAppsettings(Session session)
        {
            // Pull values from installer
            string keyVaultConnectionString = session["KeyVaultConnectionString"];
            string keyVaultUrl = session["KeyVaultUrl"];


            return ActionResult.Success;
        }
    }
}

对不起,如果xxx令人困惑。出于安全原因,我必须替换一些上下文。

1 个答案:

答案 0 :(得分:1)

因此,您似乎未在wix代码中包含自定义操作dll。请尝试以下操作,并确保包括您的CA dll。编辑CA dll名称/入口点等以匹配您的代码。

    <Fragment>
      <CustomAction Id='xxx.xxx.xxx.WindowsService.CustomAction' BinaryKey='CA123' DllEntry='SaveAppsettings' Execute='immediate'
                    Return='check'/>

      <Binary Id='CA123' SourceFile='xxx.xxx.xxx.WindowsService.CustomAction.dll'/>
   </Fragment>