By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

Compiling a single file

P: 23
I have been interested in switching from Java to C# for a long time now. I typically write small, stand alone programs for contests. Each program is completely self contained. I am used to, in Java, creating a file, say with a single class and main method, compiling it, and running it.
Since I've switched to C#, I have been using MS Visual C# Express 2008 as my IDE. It has this weird obsession with encapsulating all of my programs into "solutions" which each create a folder full of files and subdirectories, with the actual exe buried under a bin/Debug folder. What's worse, I cannot create multiple files with Main methods, since it attempts to combine them all into a single exe and complains that there are multiple entry points. All I would like is to open single .cs files, each with main methods, and compile and run them as separate .exes. Can anyone point me in the right direction?
Aug 3 '09 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 449
No's not that you're thinking....
A Project/solution resembles to just one project...and its everywhere
if you're developing a console App
Then you might switch over from your IDE to notepad and compile with The visual Studio compiler.....then there's noi problem
Or if you develop winforms app... then it might be a bit difficult from notepad.

As far as to my knowledge there's no way possible in VS IDE....
Because you might have noticed there's a Program.cs file generated with every project.. you create....
That has the main() method defined....and only that file Program.cs has the authority to define main....
and you can run any you wish...
by just changing....

Application.Run(new Form1());
Where you can change the the preference of the form to any form you wish to just the bold syntax up there...with any form class constructor....
This way you can have a single form which launches any number of forms .....

any more help ask me....
Aug 3 '09 #2

Expert 100+
P: 569
What you can do is create a Project inside the Solution for each exe you want to compile. VS2008 will then create a subfolder for each project, all containing a bin/debug folder. Each project will also have a program.cs with it's own main() method.

Aug 3 '09 #3

Expert 2.5K+
P: 3,525
Can anyone point me in the right direction?
Yeah... Quit fighting it. You can either continue to drive yourself crazy trying to force VS to work your way, or wrap your head around the organization that the rest of the .NET community uses.

You say you write lots of little programs. Great. So what is the problem? Each program is a Solution, with one Project: Your exe. Most of us might include a second Project that is the installer/setup. The installer gets configured to look at the primary output of the other project as well as install any prerequisites like registry settings, .NET frameworks you rely on and so on. Each solution is meant to be just that, a complete solution to a task. The installer that is part of solution "Alpha" is configured for that particular need. A different problem gets a new Solution, which can include one or more projects to get the job done.

As your goals get larger you will start to appreciate the layout. A Solution for a store might require a Project that is their backend database, another Project that is their WinXP cash register, another Project that is their Database Auditor program etc.

A lot of my Solutions also include an existing Project that has a lot of my generic and highly re-used functions, methods and controls. Whenever I update that generic Project, it means all of my Solutions that include it automatically get the latest version when they next open.
Aug 3 '09 #4

P: 23
Thanks ThatThatGuy, for some reason that just didn't occur to me. I'll use that approach from now on.

MrMancunian - I understand that would work, but it was kind of what I was trying to avoid. Creating an entire project for a single file seems like overkill.

tlhintoq - It's the same thing I said above. A project seems like a bit much for a single program. I understand that it would be a great organization for larger things like your store example, but it just isn't what I'm looking for here.
Aug 3 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.