I need a sample/example demonstrating how to pass a config file as a parameter to a console application in .Net
+1
A:
Pass it in command line parameters, in args[]
.
Something like this.
class Program
{
static void Main(string[] args)
{
if (args == null)
{
Console.WriteLine("args is null."); // Check for null array
}
else
{
// use args to get passed config file path
}
}
}
~~~ How to call the program ~~~
C:\ConsoleApplication1.exe "your config file path" (like C:\config\app.config)
Incognito
2010-06-06 19:37:01
A:
Do you have access to target console application source code? Is it .NET application?
If yes do next: add target app as a reference to the source application project (exe can be added like dll, there is no difference). And call some public method.
// target.exe code
namespace Target {
public class MyConfig { }
public class Program {
static void Main(string[] args) { }
public static void EntryPoint(MyConfig conf) { }
}
}
// source.exe code
namespace Source {
class Program {
static void Main(string[] args) {
Target.MyConfig conf = new Target.Config();
Target.Program.EntryPoint(conf);
}
}
}
abatishchev
2010-06-06 19:48:20