質問

I want to develop an application, App1, that gets some information & settings from the user. Then, using these settings, it should build a second application, App2. I want to have App1 build App2's exe file.

I know that one way to do this is to make a text or XML file to hold the settings and put this next to App2's exe file, but I want to embed these settings into App2's exe file instead. How can I do this using Visual Studio, the .net framework, and the C# language?

役に立ちましたか?

解決

I don't understand what do you mean by those user information and settings (some example would help), but basically, what you want to do is invoke the C# compiler as follows

var p = new Process();
p.StartInfo.FileName = @"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe";
p.StartInfo.Arguments = @"c:\aa\Test.cs";
p.Start();

These four lines invoke the c# compiler on a C# code file and produces an exe file in the output folder for your project.

MSDN provides more info on how to work with the compiler via command line. Especially, how to compile more than one file, how to compile a library, etc.

他のヒント

You can accomplish the same thing like this:

Make two applications. App2 will be the same .exe file for all cases of App1. Instead of building an .exe file, App1 will generate a configuration file containing the information and settings input by the user. This file will be read by App2. App2 will then call the appropriate functions within App2, based on the information and settings in the configuration file.

I'm trying to do the same thing for the same reasons, but using VB.NET. That's how I found this question. The only way I can thing of (other than editing the source code each time, which is what I'll be doing unless I find a better way), is to create a second program that encrypts a parameter file and give the encrypted parameter file and the exe file to the end user.

I'm still using the "editing the source method" because I want to give the user just the exe file without dealing with parameter files or encryption. There aren't many users who will need this in my case (for the moment) so I can deal with that method for now.

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