Domanda

I need to small tool in Windows environment to change an entry in appsettings.config.

It can be a cmd tool which I can write a batch file on it.

Does anyone have a clue? Thanks

È stato utile?

Soluzione

Use xmlstarlet. :) Thanks npocmaka

updates:

Here is a period of code I wrote to use xmlstarlet.

To change the file:

../bin/Config/%~1/appSettings.config

<appSettings>
    <add key="KillMobileService" value="0">
</appSetting>

to

<appSettings>
    <add key="KillMobileService" value="1">
</appSetting>

use

xml edit --pf --inplace --update "/appSettings/add[@key='KillMobileService']"/@value -v 1 ../bin/Config/%~1/appSettings.config
xml fo -t ../bin/Config/%~1/appSettings.config >../bin/Config/%~1/appSettings_new.config
del "..\bin\Config\%~1\appSettings.config"
ren "..\bin\Config\%~1\appSettings_new.config" "appSettings.config"

I use edit and format command. IIS will restart when detecting this content change.

doc link for edit command: http://xmlstar.sourceforge.net/doc/UG/ch04s03.html

doc link for format command: http://xmlstar.sourceforge.net/doc/UG/ch04s05.html

Problem solved. =w=

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top