0

I am using Wix to create MSI installers. My requirement is to pass parameters while installing msi from the command line and update' theappsettings.json` with the values passed.

To achieve this, I have added below property and component.

  <Property Id="ApplicationLog.pathFormat" />


  <Component Id="config" Guid="*">
    <File Id="appconfig" Source="$(var.BasePath)\appsettings.json" KeyPath="yes" Vital="yes"/>
    <util:XmlFile 
      Id="_pathFormat_" File="$(var.BasePath)\appsettings.json"  
      Action="setValue" 
      Name="pathFormat" Value="[pathFormat]" 
      ElementPath="/ApplicationLog/Serilog/WriteTo/Args/"
      Sequence='1' />
  </Component>

I have passed the values as follow while installing

C:\work\Installer\bin\Debug>MyService-Debug-x86.msi pathFormat="value1"

But I get below error

Failed to open XML file ....\Installer\bin\Debug\netcoreapp2.1\win-x86\publish\appsettings.json. system error -2147024786

Additional Information

There was ICE30 error,

ICE30: The target file 'l-racj8d.jso|appsettings.json' is installed in '[ProgramFilesFolder]\MyService\' by two different components on an LFN system: 'config' and 'cmpF82FCA80BBAF44D285C97F10993DEEE6'.

Which resolved by changing the ICE validation-> Suppress ICE validation

But why installer unable to open the json app settings? I am running the installer in administrator mode.

Update

I have changed $(var.BasePath) to '[INSTALLDIR]'

  <Component Id='config' Guid='*'>
    <File Id='jsonconfig' Source='[INSTALLDIR]appsettings.json' KeyPath="yes" Vital="yes"/>
    <util:XmlFile Id='xpathFormat' File='[INSTALLDIR]appsettings.json'
                  Action='setValue' Name='pathFormat' Value='[ApplicationLog.pathFormat]'
                  ElementPath='/ApplicationLog/Serilog/WriteTo/Args/' Sequence='1' />
  </Component>

But I am getting

The system cannot find the file '[INSTALLDIR]appsettings.json'.

Is it because appsettings.json is not yet copied to [INSTALLDIR]?? If yes, then how to achieve this?

kudlatiger
  • 3,028
  • 8
  • 48
  • 98
  • Using `XmlFile` to update JSON file? How does that work? – Dialecticus Jul 30 '19 at 07:04
  • I'm not familiar with Wix, but I would add: 1) Properties passed on the command line should be upper case (i.e, a public property - PATHFORMAT). 2) Why would you want to suppress ICE validation? 3) Make sure you schedule the XmlFile part to run after the InstallFiles standard action. 4) What @Dialecticus said! – Captain_Planet Jul 30 '19 at 07:27
  • How to schedule XmlFile to run after standard actions? Is there post-install actions supported by Wix? – kudlatiger Jul 30 '19 at 08:20
  • @Dialecticus I am not sure, there is no JsonFile component in wix – kudlatiger Jul 30 '19 at 10:14
  • There is no such thing. It does not exist. You have two options, either make your own custom action, or update the configuration from your app (instead of from msi). So, your app would somehow detect that config should be changed, and must have the parameters to update, and maybe even have to do this in a new process with admin privileges. – Dialecticus Jul 30 '19 at 10:42
  • Maybe there is something of use on github, or nuget, or elsewhere. – Dialecticus Jul 30 '19 at 10:44
  • Okay, I found one solution approach here https://stackoverflow.com/questions/23805767/wix-custom-actions-reading-parameters-from-an-xml-file but not sure from where he got "Session" as parameter – kudlatiger Jul 30 '19 at 10:55
  • Every custom action has only that one parameter. A custom action must then read actual parameters from some table within msi using that one parameter. – Dialecticus Jul 30 '19 at 15:29

0 Answers0