lllgnslbdllssr
Posts: 6
Joined: Tue Jul 12, 2022 11:56 am

JSON file not edited during/after installation

Hi, I've created an appsettings.json and I have a field that is set by [Property]. I set this property using a Custom Action "Run PowerShell inline Script", but after the installation, this field in appsettings.json file is empty.

The powershell script is:

Code: Select all

$dbPassword = AI_GetMsiProperty DB_PASSWORD
$errorMessage
$connectionString
 
if ([string]::IsNullOrEmpty($databaseNamedInstance)) 
{
	$errorMessage = "Database Name cannot be empty!"
}
else 
{
	if ($useIntegratedSecurity -eq "useIntegratedSecurity") 
	{
		$connectionString = "Server=" + $databaseNamedInstance + ";Database=thisDB;Trusted_Connection=True;MultipleActiveResultSets=true;Encrypt=true;TrustServerCertificate=true;"
	}
	else 
	{
		if ((-not [string]::IsNullOrEmpty($dbUser)) -and (-not [string]::IsNullOrEmpty($dbPassword)))
		{
			$connectionString = "Server=" + $databaseNamedInstance + ";Database=thisDB;User id=" + $dbUser + ";Password=" + $dbPassword + ";MultipleActiveResultSets=true;Encrypt=true;TrustServerCertificate=true;"
		}
		else
		{
			$errorMessage = "Database username and password cannot be empty if you don't use integrated security"
		}
	}
}
 
if (-not [string]::IsNullOrEmpty($errorMessage)) 
{
	AI_SetMsiProperty CHECK_DB_CONNECTION_PARAMETERS "false"
	[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
	[System.Windows.Forms.MessageBox]::Show($errorMessage)
}
else
{
	AI_SetMsiProperty CHECK_DB_CONNECTION_PARAMETERS "true"
	AI_SetMsiProperty DB_CONNECTION_STRING $connectionString
}
This script works because I print DB_CONNECTION_STRING value and it is populated.

What am I doing wrong?
Liviu
Posts: 1049
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: JSON file not edited during/after installation

Hello,

This can happen if the PowerShell script is scheduled after the json file is created/updated.

Can you please check if you scheduled the script before the Add resources action group?

Otherwise, can you please send us the .AIP (setup project) file by email to support at advancedinstaller dot com so we can further test and investigate this?

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”