У меня есть проект, который, прежде чем он может быть запущен, должен быть правильно настроен файл appsettings.json.
До сих пор я некоторое время гуглял и не смог найти решение.Я использовал высокую температуру, чтобы перенести необходимые библиотеки в каталог установки.Чтобы отредактировать этот файл json, я изначально:
создал пользовательское действие для сериализации моделей в файл appsettings.json, но по какой-то причине это пользовательское действие вызвало ошибку, которую я не смог отладить(Погуглил и нашел 3 разных решения, но, к сожалению, никто из них не смог мне помочь)
Я решил открыть файл 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 сбивает с толку.По соображениям безопасности я должен заменить часть контекста.