tag:help.appveyor.com,2012-11-13:/discussions/suggestions/1097-json-settings-files-supported-in-deploymentAppVeyor: Discussion 2018-08-27T20:42:29Ztag:help.appveyor.com,2012-11-13:Comment/407954572016-09-21T20:19:52Z2016-09-21T20:19:52ZJson settings files supported in deployment<div><p>When <code>parameters.xml</code> is used it's "baked" into
resulting Web Deploy package and <em>then</em> you can specify
parameters during deployment. So, you can use the same immutable
package and deploy it over and over to multiple environments.</p>
<p>I'm not very familiar with <code>appSettings.json</code> - do
they follow the same approach or it's build-time thing?</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/407954572016-09-21T21:43:56Z2016-10-05T12:20:44ZJson settings files supported in deployment<div><p>So they do it at runtime, but it would be amazing if you this
could be done during an appVeyor deploy as json is the future, xml
is dead in the water....</p>
<h1><a name="proposed-solution" class="anchor" href="#proposed-solution"></a>Proposed solution</h1>
<p>You might have a json settings file
<code>appSettings.json</code> with:<br></p>
<pre>
<code>{
"first": "dev var",
"second": {
"third": "dev var"
}
}</code>
</pre>
<p>And then you could have an appveyor deployment json file next to
it called <code>appSettings.appveyor.json</code>:</p>
<pre>
<code>{
"first": "%Appveyor_Deployment_Env_Var%",
"second": {
"third": "%Appveyor_Deployment_Env_Var%"
}
}</code>
</pre>
<p>Then these 2 files are merged, with properties in the appveyor
file overwriting any matching properties in the actual settings
file. The way Asp.Net Core merges config you could just overwrite a
small part of the config file like this:</p>
<pre>
<code>{
"second": {
"third": "%Appveyor_Deployment_Env_Var%"
}
}</code>
</pre>
<p>Asp.Net Core is making a huge push into the json space for
configuration as its much more natural to express settings objects
in json.</p>
<h1><a name="current-solution-we-have-in-place" class="anchor" href="#current-solution-we-have-in-place"></a>Current solution we have in
place</h1>
<p>Our current solution is the following:</p>
<p>Deployment environment variables configured in appveyor.</p>
<p>Node script to update the json settings called
<code>appSettings.appveyor.js</code>:<br></p>
<pre>
<code>var fs = require('fs');
patchSettings('appSettings.json');
function patchSettings(jsonPath) {
// parse file<br> var json = fs.readFileSync(jsonPath, 'utf8');
var settings = JSON.parse(json.substring(json.indexOf('{')));
// apply settings
settings.first = process.env.Appveyor_Deployment_Env_Var;
settings.second.third = process.env.Appveyor_Deployment_Env_Var;
// save file
fs.writeFileSync(jsonPath, JSON.stringify(settings, null, '\t'));
}</code>
</pre>
<p>Then we run that with a <code>deploy.ps1</code> script during
the appveyor deployment:<br></p>
<pre>
<code>node appSettings.appveyor.js</code>
</pre></div>leecheneler1tag:help.appveyor.com,2012-11-13:Comment/407954572016-09-22T21:37:56Z2016-09-22T21:37:56ZJson settings files supported in deployment<div><p>Thanks for your thoughts!</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/407954572018-06-18T05:43:26Z2018-06-18T05:43:27ZJson settings files supported in deployment<div><p>How do we run this <code>deploy.ps1</code> script during the deployment?</p></div>Alissontag:help.appveyor.com,2012-11-13:Comment/407954572018-06-18T18:32:03Z2018-06-18T18:32:03ZJson settings files supported in deployment<div><p><strong>@Alisson</strong> Can you clarify more about your deployment? Is it <strong>inline</strong> or <strong>environment</strong> deployment (difference described <a href="https://www.appveyor.com/docs/deployment/#overview">here</a>)? Is it <a href="https://www.appveyor.com/docs/deployment/agent/">agent deployment</a>?</p></div>Ilya Finkelshteyn