MiguelOM
Posts: 12
Joined: Mon Sep 19, 2022 8:01 am

Working with conditionals in JSON files

Hello!,

I am trying to create an installer (enterprise), and I don't know how to set a value into an appsettings.json depending on which DB configuration the user set up.

As ConnectionString changes depending on the provider, what I need is to set the value of ConnectionString key "DbConnection" on my appsettings according to the provider [PROVIDER_PROP] chosen by the user throughout the installation.

I have tried to add a new item into the ConnectionString section, and set a condition, but I need the same key name (DBConnection) in any case (SQL Server, MySQL or Oracle) and cannot do it.

Thanks in advance for your support.

Best Regards,

Miguel
Catalin
Posts: 6584
Joined: Wed Jun 13, 2018 7:49 am

Re: Working with conditionals in JSON files

Hello Miguel and welcome to our forums,

Indeed, you can not have the same name for a node.

However, you can work this around by using installer properties.

For instance, you can create two properties in the "Properties" page, like this:
properties.png
properties.png (14.08 KiB) Viewed 4012 times

You can then configure your JSON file as it follows:
DBConnection.png
DBConnection.png (7.75 KiB) Viewed 4012 times

This way, you can use the same name.

Now, of course, you need to condition each node so only one gets installed.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
MiguelOM
Posts: 12
Joined: Mon Sep 19, 2022 8:01 am

Re: Working with conditionals in JSON files

Thank you so much!

It was the first think that I thought, but I wanted to know if I could do this kind of conditions.

Best Regards,

Miguel
Catalin
Posts: 6584
Joined: Wed Jun 13, 2018 7:49 am

Re: Working with conditionals in JSON files

You are always welcome, Miguel!

Glad I could assist.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”