Reputation: 245
I have a winforms application that takes in input from a gui and runs the logic to give the output.
I want to make a console version of the same application, where I specify the file which has the input values (instead of providing through gui) and run the winform application logic and write the output into a file.
My winform application produces a dll that I wish to use so that any changes in my application is reflected in the console application as well.
Please suggest as to how can I achieve this. I do not know how to proceed.
Upvotes: 1
Views: 367
Reputation: 125187
You don't need to do an extra job.
Option 1: Environment.GetCommandLineArgs()
You can simplyt use Environment.GetCommandLineArgs()
to and parse it and use parameters as you need.
For example:
Environment.GetCommandLineArgs().ToList()
.ForEach(x =>
{
MessageBox.Show(x);
});
For example you can use your program from command line just like this:
yourProgram.exe param1 "another param" anotherParam
yourProgram.exe "d:\myfile.txt"
Option 2: static void Main(params string[] args)
Also you can change main signature this way static void Main(params string[] args)
and use args this way:
args.ToList()
.ForEach(x =>
{
MessageBox.Show(x);
});
And use it this way:
yourProgram.exe param1 "another param" anotherParam
yourProgram.exe "d:\myfile.txt"
Note:
Upvotes: 3
Reputation: 71
Simply add another project (console application) to your solution and put the IO operations there. The logic stays in the class library.
Upvotes: 0