An extension to Windows® installer XML (WiX) to create or modify JSON-formatted files during an installation.
To Use this Wix Extension
- Add a package reference to your project with
dotnet add package WixJsonFileExtension
- Add a schema reference inside your wxs file to
xmlns:Json="http://schemas.hegsie.com/wix/JsonExtension"
- Use the JsonFile XML element inside your wxs to update your target jaon file:
<Json:JsonFile Id="appSettingsSetBooks" File="[#JsonConfig]" ElementPath="$.store.book" Value="[MY_BOOKS]" Action="replaceJsonValue" />
Possible Actions include
- deleteValue
- setValue (this is the default if one isn't specified)
- replaceJsonValue
- createJsonPointerValue
All actions use JSONPaths in their ElementPaths unless specified in their action i.e. createJsonPointerValue
- Refer to the product.wxs inside the TestJsonConfigInstaller project here for examples on how to manipulate your JSON file inside of an MSI
NB: There are a lot of complex scenarios when using JSONPath (like multi-select inside arrays etc, which don't currently work) try to keep use cases simple where possible or report the issue here and I'll try and see if it can be implemented.
Windows® installer XML is an open-source set of tools to create Windows® software installation setups (*.msi), using XML files to define the content and behavior of the setup. One important step in most setups is to modify configuration files to reflect either settings specified during the setup by the user, or other settings specific to the individual installation. Windows® installer has built-in actions to modify the classic ini-files (*.ini), and WiX provides extensions (and the required custom actions) to modify XML files, and in particular the Application Configuration files (*.exe.config or *.dll.config) used by Microsoft® .NET applications. Today, a third format has become popular, especially in web applications: JSON - JavaScript Object Notation. Often used in networking scenarios (REST services, JQuery, etc.), it is also used as a local data store format, including configuration files. Especially .NET Core relies heavily on JSON-formatted configuration files, both during development and runtime.
This extension for WiX provides methods to modify JSON files (*.json) during a software installation. The new XML elements provided by this extension - JsonFile, work very similar to the existing extensions for XML files, XmlFile
WixJsonFileExtension uses jsoncons by Daniel Parker to read and manipulate JSON files.