6

I want to modify values in an existing json file.

When I run my installer I type server name which points to my API. After I typed server name I want to add that value in app settings json file.

enter image description here

enter image description here

enter image description here

Alex
  • 873
  • 1
  • 11
  • 26
  • Do this in a Custom Action – Morten Frederiksen Sep 21 '17 at 12:41
  • Can you be more specific? – Alex Sep 21 '17 at 13:01
  • That would take hours and fall in the do it for you category. I would seriously consider rewriting your code to store your configuration data in XML and then transform it to JSON if needed on load. – Christopher Painter Sep 21 '17 at 16:40
  • 1
    The WPF tag suggests you are installing an application (that is, a program with a UI and run by a user). So, as an alternative, implement this functionality as a first-run or re-configure operation in the application. Of course, this wouldn't work well if only an administrator would have the knowledge or permission to set the configuration. – Tom Blodget Sep 23 '17 at 23:13
  • @ChristopherPainter I disagree. Modern frameworks are moving to JSON files for configuration (.net core for example). Seems like WIX is the installer MS is sticking with so it really needs JSON and XML support. The correct answer is unfortunately custom actions. – spyder1329 Jun 13 '19 at 23:28
  • FWIW is a custom action. It's provided by a WiX extension because MSI doesn't do it natively. It's just a custom action provided by WiX without having to do it yourself. Writing custom actions that are declarative, transactional and bullet proof are hard and take a lot of testing. Maybe you could submit a WIP to the wix-devs mailing list offering to write it. – Christopher Painter Jun 13 '19 at 23:39

2 Answers2

2

(SOLUTION)

http://dotnetbyexample.blogspot.ro/2010/11/wix-configurable-search-replace-custom.html

You need to create a wix project (Custom Action Class Library) create logics, after that you need to use dll in Product.wxs (Installer project) like in example.

Good luck!

PS: if you want to change one property from file, you should have something like this:

enter image description here

Alex
  • 873
  • 1
  • 11
  • 26
  • help here https://stackoverflow.com/questions/57294132/how-to-update-appsettings-json-from-wix-custom-actions-with-the-values-passed-as – kudlatiger Aug 01 '19 at 10:58
0

WixJsonExtension is a WiX extension which provides methods to modify JSON files during installation. The JsonFile element works very similar to the XmlFile element.

Rami A.
  • 9,896
  • 4
  • 42
  • 84
  • That library is marked as "Under construction, non-functional" (as at today). Would be good to see it working though, as I need this type of Custom Action today. – pridmorej Sep 13 '21 at 10:29
  • I was able to get it working as expected when using pull request #1 https://github.com/NerdyDuck/WixJsonExtension/pull/1 which is from a fork of the repo here: https://github.com/hegsie/WixJsonExtension. If it doesn't work for you, you may want to create a new issue in that repo. – Rami A. Sep 13 '21 at 17:30