I've got a project that before it can be run the appsettings.json file must be configured correctly.
So far I've googled for a while and was unable to find a solution. I have used heat to migrate the required dlls over to the install directory. To edit this json file I originally:
Created a Custom Action to serialize models into the appsettings.json file but for some reason this custom action was causing an error that I couldn't debug (Googled and found 3 different solutions, but sadly none of them were able to help me)
I have decided to open the json file after installation, which works but I am unable to find a way to have the notepad opened as admin to edit the json file(I have already tried a bunch of solutions for this one too)
Which solution should pursue? Maybe I'm just bad at googling for solutions but maybe some insight as for which solution would be best practice would help.
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>
Error Log From 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, ,
Custom Action
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;
}
}
}
Sorry if the xxx makes it confusing. For security reasons I have to replace some of the context.