Launching the console application several times with various configuration files

I wrote a console application ( app.exe ) that has settings in the configuration file ( app.exe.config ).

I need to run this several times with differnet settings in the configuration file.

The most inconvenient solution I'm using now is to rename both, app1.exe , app1.exe.config , etc., and then schedule a separate task for each application so that it works in the morning.

What I would like to do is have a main configuration that refers to different configs, and then only has one app.exe master.app.exe.config , which then launches app.exe as many times as there are links in the main configuration.

I do not want to do this in code, as I would like to explain to users how to support the configuration file and what it ...

Setting example:

 <!-- datstr ="" => current date, datstr="yyyymmdd" => specific date, datstr ="yyyymmdd,yyyymmdd, etc" => multidate, DONT USE "yyyymmdd","yyyymmdd" --> <add key="datstr" value=""/> 

Is it possible? Is there a better way?

+4
source share
1 answer

From what I can understand, I believe that you do not have the best architecture for the work you want to do.

I would suggest extracting the configuration of a specific instance from the app.exe.config file and transferring it to separate configuration files for specific instances. Then you download the correct configuration file using the command line.

Instead

 app1.exe (and app1.exe.config) app2.exe (and app2.exe.config) app3.exe (and app3.exe.config) 

The result is:

 app.exe (app.exe.config) instance1.xml instance2.xml instance3.xml 

and run them (for example):

 app.exe -c instance1.xml app.exe -c instance2.xml app.exe -c instance3.xml 

(Note that using -c and .xml is for example purposes only - use what works for you)

This has advantages such as:

  • Scheduling can be left up to the Windows Task Scheduler.
  • Users can more easily edit and test various configuration files, etc.
  • Users do not edit the app.config file, so it can be protected from accidental changes.
  • You only need to give detailed instructions on editing specific instance files (although I will hate you if you do not document the app.config file ;-))
+3
source

Source: https://habr.com/ru/post/1497222/


All Articles