1

I have a requirement to build a container C# WinForm Application which will spit out .exe files of another WinForm Application on a button click event.

For eg: I have one Winform App named ProjectA which accepts one startup argument. Now I have a container WinForm App named ProjectB. I want to generate ProjectA.exe programmatically within ProjectB by passing the required parameter to ProjectA app on the button click.

Could not find anything relevant about this on Google. Can anyone throw in some light to achieve this.

Please note that both the Winforms Application must be written in C#.

I have one very vague thought of using MSBuild Command to build ProjectA which in turn will generate its .exe However I am not too clear on this.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • I can only point you in the right direction on this as it was done in a previous employer of mine. But yes you need to use MSBuild.exe. E.g. C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe. This accepts parameters for solution location, build configuration, platform etc... – Wheels73 Jun 05 '18 at 10:36
  • Thanks @Wheels73. Do you have any references or documentation about it? I have never used MSBuild till now. So I am a bit new to this whole thing. – Harshit Gandhi Jun 05 '18 at 10:47
  • Nope sorry. As i said, it was an old company. I've just done a quick search. This topic is covered on this site. try https://stackoverflow.com/questions/7264682/running-msbuild-programmatically – Wheels73 Jun 05 '18 at 10:51

2 Answers2

0

It is not necessary to mess with MSBuild for this. You may generate your program's code as a string and then generate your executables on the fly:

https://support.microsoft.com/en-us/help/304655/how-to-programmatically-compile-code-using-c-compiler

rs232
  • 1,248
  • 8
  • 16
  • I think this will have huge impact if we talk about scalability and maintenance of a project. Also debugging using a string will be an issue. Anyways thanks for your reply. Appreciate it. – Harshit Gandhi Jun 06 '18 at 04:49
0

As an example:

Process.Start(@"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe", @"d:\app1\app1.sln");

Another Example:

Process.Start(@"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe", @"d:\app1\app1.sln /t:Rebuild /p:Configuration=Debug;TargetFrameworkVersion=v4.0");

put the above code on your button click.

Hossein Golshani
  • 1,847
  • 5
  • 16
  • 27