Wix 工具集 - 配置文件的最佳实践?
Wix Toolset - Best practice for config file?
我有一个项目,在它可以 运行 之前,必须正确配置 appsettings.json 文件。
到目前为止,我已经用谷歌搜索了一段时间,但未能找到解决方案。
我已经使用 heat 将所需的 dll 迁移到安装目录。
要编辑此 json 文件,我最初是:
创建了一个自定义操作来将模型序列化到 appsettings.json 文件中,但由于某种原因,这个自定义操作导致了一个我无法调试的错误(谷歌搜索并找到了 3 种不同的解决方案,但遗憾的是 none 他们能够帮助我)
我决定在安装后打开 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 让人感到困惑。出于安全原因,我必须替换一些上下文。
看起来您没有在您的 Wix 代码中包含您的自定义操作 dll。请尝试以下操作并确保包含您的 CA dll。编辑 CA dll name/entry 点等以匹配您的代码。
<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>
我有一个项目,在它可以 运行 之前,必须正确配置 appsettings.json 文件。
到目前为止,我已经用谷歌搜索了一段时间,但未能找到解决方案。 我已经使用 heat 将所需的 dll 迁移到安装目录。 要编辑此 json 文件,我最初是:
创建了一个自定义操作来将模型序列化到 appsettings.json 文件中,但由于某种原因,这个自定义操作导致了一个我无法调试的错误(谷歌搜索并找到了 3 种不同的解决方案,但遗憾的是 none 他们能够帮助我)
我决定在安装后打开 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 让人感到困惑。出于安全原因,我必须替换一些上下文。
看起来您没有在您的 Wix 代码中包含您的自定义操作 dll。请尝试以下操作并确保包含您的 CA dll。编辑 CA dll name/entry 点等以匹配您的代码。
<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>