質問

I searched and found only fragments of the answer. I am building tool for distribution across the studio. I have an .exe command line program ( a tool which that converts asset formats ) inlcuded as a resource in my VS project.

Based on another thread, I set the inluded .exe's "Copy To Output Directory" property to "copy if newer"; So that it will be included when others install it.

Now i want to call this executable, with arguments, by passing a string that is a built command line, such as

"C:\path\to\myProgram.exe -inputFilename -outputFilename -options"

the problem: what do I really need for C:\path\to\myProgram.exe ? where is my command line executable going to end up installed on the end user's machine?

or does embedding it as a resource open a new way of calling it(with args)?

役に立ちましたか?

解決

Copying to the output folder guarantees that the "resource" will have a relative location to your executable. With the method of copying to the output folder, you can use the following code to get the location of your main executable:

String baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

At which point you can use

Path.Combine(baseDir, "myProgram.exe")

to get the final path. If it is in a "tools" folder, you would have to include that in the second argument (that argument is the relative path to your seperate program). The command line arguments go into the ProcessStartInfo object.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top