I have a C# based solution in Visual Studio 2008 for a given problem domain. This solution has 1 + 5 projects. The first project is for resources that spans across the other 5 projects.
Each project has multiple forms. By default, the build generates one executable per project. What I want rather is each form, which has no mutual dependency to the rest, to produce a stand-alone executable.
I am aware that I could break each of the 5 prime projects into multiple projects and set "Startup Project" to "Multiple startup projects" and achieve my objective. But that will over-populate the solution with the number of projects increasing to mid double digits. I do not want to pursue the route of having a separate solution for the each of the 5 projects.
Right now I invoke Application.Run as follows to accomplish my goal:
Application.Run(new fooForm());
and when I need to create an executable for another independent form, I change the form value to
Application.Run(new barForm());
and so on until I need another shot of espresso.
Any hack to accomplish what I intend without me having to jump out of the window?
Perhaps it is an option for you to leave everything in one EXE file per project and decide at running time which Form to start with. For example, you could make copies of your EXE file with different names, determine the name of the EXE from
Assembly.GetExecutingAssembly().Location
and use this information to select the Form you put to 'Application.Run'.
Or, you don't make copies and call your EXE with appropriate command line parameters. It depends on how your users select between the different database reports.
Edit: here is a simple example (untested):
[STAThread]
static void Main(string[] args)
{
if(args.Length<1)
return;
if(args[0]=="Form1")
Application.Run(new Form1());
else if(args[0]=="Form2")
Application.Run(new Form2());
}
Create a batch-file per form/exe to compile the project using the command-line compiler (csc.exe for C#), specifying which class (form) contains the Main-method to use.
public partial class Form2 : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
Compile an executable for form2 using something like:
csc.exe /out:Form2.exe Form2.cs Form2.designer.cs /Main:WindowsFormsApplication1.Form2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With