1

I have a console app that I have to launch from my code. This app has a configuration file that locates in the same folder. If I launch console app manually it finds the configuration file and everything goes fine. But when I launch it as a process in my code it tries to find configuration in my app's folder, so I need to copy it to Debug/Release folder. Can I avoid this behavior because I want this console app to locate independently as a module?

Ivan Khorin
  • 827
  • 1
  • 5
  • 17
  • So you have DirectoryA => {DDL_A, Config_A} and DirectoryB => {DDL_B, Config_B}. And A is calling B. B need for example a connnexion string that is only in Config_B. Or is A trying to get Config_B. – Drag and Drop Oct 28 '20 at 09:50
  • Related : [Accessing App.config in a location different from the binary](https://stackoverflow.com/questions/75978/) – Drag and Drop Oct 28 '20 at 09:53
  • Thank's for your replies, InBetween gave me a question. Config file was not an "App.config", it was a file that just read from console app and parsing manually. – Ivan Khorin Oct 28 '20 at 09:58
  • `Assembly.GetExecutingAssembly().Location` will give you the current location of the dll executing this code. – Drag and Drop Oct 28 '20 at 10:02

2 Answers2

2

You need to define the WorkingDirectory of your process. Check ProcessStartInfo.WorkingDirectory for more information.

In your case you probably want to set UseShellExecute to false and set the working directory to the executable's location.

InBetween
  • 32,319
  • 3
  • 50
  • 90
0

You may be able to load the file from the executing assembly. Assembly.GetExecutingAssembly().Location will give you the current location of the ddl executing this code.

var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
Drag and Drop
  • 2,672
  • 3
  • 25
  • 37