Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Go Back  Xtreme Visual Basic Talk > > > Process of Compiling VB.Net Source Code


Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2008, 08:21 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default Process of Compiling VB.Net Source Code


Hello,
I have been searching the web for information regarding the compilation process of my VB.Net source code. I found many links that were very helpful, and I benefited alot. But there are some questions that still confuse me.

I, the programmer, provide the source code. My souce code is semi-compiled by the Visual Basic Compiler into an Intermediate Language (IL) version. The result is as assembly.
Question # 01: Is the IL version an exe file?
Question # 02: I usually find a .exe file in the Debug folder; is this the IL version?
Question # 03: When I say:
Code:
Imports System.IO
Am I referencing the .Net Framework?

Then, my users run the assembly. The Common Language Runtime takes the IL version and does a final, Just-In-Time compile. The result is a native code. application runs!
Question # 04: Can I fully compile my source code, and get the native code to give it to my users?
Question # 05: Does the word "executable" mean a program that runs by itself without the need for other things...? What is the difference between "executable" and "stand-alone"?

My friend, who is a Computer Engineer and dislikes Microsoft, argues that I should not say: "somefilename.exe" unless it can run by itself.
He also argues about the size of the Primary Output .exe file that is copied to the users. He says that it's a too large file given the source code, and we can use WinZip to compress it to a relatively high percentage compared to other exes, which, he says, proofs that it's full of Microsoft stuff!
I believe that he is wrong somehow, but I don't have a convincing reply.

Thanks a lot.
Reply With Quote
  #2  
Old 04-15-2008, 08:50 AM
AtmaWeapon's Avatar
AtmaWeaponProcess of Compiling VB.Net Source Code AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

1-2. Is the IL version of the code an executable file/Is the .exe file the IL version of the file?

Yes and no. The code is really generated in two steps: first the code is converted to IL, then it's wrapped with a Windows PE header. The .exe file that is generated is the assembly metadata, IL, and PE header in a single file. When you run the executable, it instructs Windows to jump into the .NET CLR, which takes over execution of the IL.

3. Is this [...] referencing the .NET Framework?

Yes and no. What this tells the compiler is that all classes in the namespace System.IO should be included when resolving scope. This means you can say StreamReader instead of System.IO.StreamReader. I'm not entirely certain what impact this has on the final output of the build process.

4. Can I compile my .NET source into native?

Yes and no. There is a utility (ngen.exe) that will convert a .NET assembly from being interpreted IL to using native code. Your application will still require the .NET Framework on the target machine. There's a lot of performance disadvantages to using ngen.exe, so it's generally unused.

5. What is the difference between "executable" and "stand-alone"?

It depends on the context, but I think the most general answer is that a stand-alone executable runs without reliance on any external libraries. How strict you make that definition determines how "stand-alone" the application is. For example, even a "Hello World" program in C relies upon the stdio library. If we say only programs that use standard C headers are stand-alone, then any Windows application is not standalone since they rely on the Windows-specific windows.h and several other libraries, and in fact probably won't run on a system that doesn't have user32.dll. One level above that, what if we have a C++ application that relies not only on Windows DLLs, but some custom third-party DLLs? This is kind of where .NET lives: every .NET application requires that the client machine has a compatible .NET Framework installed.

Your friend is taking too much credit for his "Computer Engineer" title. Where I study, Computer Engineers learn the basics of software development but have a more intense focus on circuit design. I would not expect him to be able to speak with authority on how software works compared to, say, a Computer Scientist or Software Engineer, though in no case should any of those three degrees study .NET in enough detail to answer those questions. He's still wrong. If you don't name the file ".exe", Windows won't know it's an executable and it won't run. The extension does nothing to describe the contents of the file, that's what the name is for. The file extension is to tell Windows what program to use to run the file. This is why Unix/Linux environments rarely use file extensions.

He is slightly correct about the compression. Many applications use an executable packer like upx to compress (and sometimes encrypt) their applications. This can dramatically reduce the size of your executable with a negligible effect on resource usage. However, I know of no executable packer for .NET applications. Their PE format is different from the standard Windows PE format, and would require some special handling that apparently no one has tackled.

With respect to whether it's "full of Microsoft stuff", the ILDasm tool ships with the .NET SDK and will show you the IL inside of any .NET assembly. Tell him to feel free to pore over the IL code and find the "Microsoft Stuff". Furthermore, I just compiled a "Hello World" C++ and VB .NET application, and the C++ was 9KB vs. the VB .NET application's 11KB. I'd say they both have fat to trim, but I don't think that's a dramatic increase in size.
Reply With Quote
  #3  
Old 04-15-2008, 10:31 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

AtmaWeapon, Thank you very much and sorry for late reply...
All answers are very clear.

Quote:
For example, even a "Hello World" program in C relies upon the stdio library.
Does it run everywhere? Compare: a "Hello World" VB.Net will not run everywhere.
Seems that the "Hello World" C program is very similar to VB6 .exe, which is considered by many beginners as "completely portable" between Windows OS.

Quote:
Furthermore, I just compiled a "Hello World" C++ and VB .NET application, and the C++ was 9KB vs. the VB .NET application's 11KB.
When it comes to C, or C++, I get lost!
Does the C++ 9KB application need the .Net Framework to run? Did you develop it using Visual Studio .Net? Is there another way to develop C++ applications that have nothing to do at all with MICROSOFT .Net Framework?
Reply With Quote
  #4  
Old 04-15-2008, 11:07 AM
AtmaWeapon's Avatar
AtmaWeaponProcess of Compiling VB.Net Source Code AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by Adel99 View Post
Does it run everywhere? Compare: a "Hello World" VB.Net will not run everywhere.
Seems that the "Hello World" C program is very similar to VB6 .exe, which is considered by many beginners as "completely portable" between Windows OS.
It all depends on your definition of "run everywhere" and "completely portable". If you use the GNU C compiler and its header files, you can produce executable files that will run on a particular CPU architecture and in theory will work on both GNU *nix environments and Windows environments. Still, if the program is compiled for the x86 architecture and you try to run it on a PowerPC-based machine or some other architecture, it will probably fail.

Only truly trivial applications can be portable in this nature. Even in the *nix environments, you have to use make to build a program to ensure it will work on your system. You can write code to be portable, but in many cases it still needs to be built with particular options enabled in order for it to run on a given machine. For example, I play the game NetHack, which is compiled in C. To get a working binary for NetHack, I have to download the source, set some options in the configuration file, and then use make to compile it. This is because in many cases, Linux and Windows use completely different system calls for a task, and it's impossible to write the code in such a way that it always does the right thing. The code is written similar to this (with much more macro stuff to make it actually work):
Code:
#if WIN32
    windows_system_call(windowsOptions);
#elif LINUX
    linux_system_call(linuxOptions);
#endif
Some languages get around this, Java is one of them, because applications are compiled to .class files which only contain bytecode to be interpreted by the Java VM. From time to time, people encounter code that just doesn't work right on a certain VM, so even Java's not immune. Also, Java programs require the installation of a Java VM, so one could say they can't run without extra work.

Most scripting languages produce portable code as well; for example Perl and Ruby scripts tend to run fine on whatever system so long as you aren't using a platform-specific code module like Perl's Win32 one. Still, the scripting language won't run without installation of the runtime, so one could say they aren't truly portable.

It is quite difficult to make a truly portable application; you're better off ignoring the statement as a detriment to .NET because true portability is impossible given the current set of programming languages. C/C++ come close, so long as you consider "I have to compile the code" to be satisfactory.

Quote:
When it comes to C, or C++, I get lost!
Does the C++ 9KB application need the .Net Framework to run? Did you develop it using Visual Studio .Net? Is there another way to develop C++ applications that have nothing to do at all with MICROSOFT .Net Framework?
No, the C++ application I made was not reliant upon the .NET framework; the program in its entirety was:
Code:
#include <stdio>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
}
It should work on any system with a standards-compliant C++ compiler, so you don't need to use Visual Studio to compile it. I used Visual Studio because I don't have easy access to another compiler at the moment, but I'd venture a guess that the GNU compiler could make a smaller exe.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 04-15-2008, 11:49 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Thank you very much, AtmaWeapon. I am speechless; thank you.
Reply With Quote
  #6  
Old 04-15-2008, 02:27 PM
cugone cugone is offline
Centurion
 
Join Date: Nov 2007
Posts: 160
Default

It should probably be pointed out that the final filesize is also inflated if you compile and distribute the DEBUG version versus the RELEASE version.

Similar in C++ IDEs as leaving the "include Trace and Debug" checked.
Reply With Quote
  #7  
Old 04-15-2008, 03:20 PM
AtmaWeapon's Avatar
AtmaWeaponProcess of Compiling VB.Net Source Code AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

The executables I tested were both release mode executables, though I didn't do anything to the default settings so I had no extra optimizations turned on. Generally I think optimization for speed is favored over optimization for size anyway.
Reply With Quote
  #8  
Old 04-15-2008, 03:56 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Quote:
Originally Posted by AtmaWeapon View Post
The executables I tested were both release mode executables, though I didn't do anything to the default settings so I had no extra optimizations turned on. Generally I think optimization for speed is favored over optimization for size anyway.
Sorry AtmaWeapon, I have been trying to compile this code:
Code:
Module Module1
    Sub Main()
        Console.WriteLine("Hello World!")
    End Sub
End Module
I have changed "Debug" to "Release" and vice versa using the Standard Toolbar. after the two compilation, I had two folders in the bin folder. Both exes are 24 KB!
Reply With Quote
  #9  
Old 04-15-2008, 04:46 PM
AtmaWeapon's Avatar
AtmaWeaponProcess of Compiling VB.Net Source Code AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Weird. What version of VS are you using? I'm just using a basic console application compiled through VS 2008, and I even tried removing all project references and imported namespaces, but it had no effect. I get a final size of 11 KB. Also make sure it was a console application and not a Windows Forms application; default WinForms applications come with the application framework which does include a lot of stuff you might not necessarily want.
Reply With Quote
  #10  
Old 04-15-2008, 05:20 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Quote:
What version of VS are you using?
Visual Studio .Net 2005 Professional.
Quote:
I'm just using a basic console application
Me too.
Quote:
and I even tried removing all project references and imported namespaces.
I had no import code.. I showed you all the code.

I change the solution configuration (Debug/Release), and then run the application by pressing F5 or the Start Debug button. Then I go to the "bin" folder where I find two folders: Debug and Release.
I also tried Clean and then Build (also tried Rebuild). all gave a 24 KB exe. I also checked the "obj" folder all exes are 24 KB.

ScreenShot

YOURS
Reply With Quote
  #11  
Old 04-15-2008, 05:38 PM
AtmaWeapon's Avatar
AtmaWeaponProcess of Compiling VB.Net Source Code AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Ahh, there's the difference. I just compiled the same code in VS 2005 and got a 24 KB executable. Looks like the VS 2008 compiler's a lot more efficient.
Reply With Quote
  #12  
Old 04-15-2008, 05:51 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Quote:
Originally Posted by AtmaWeapon View Post
Ahh, there's the difference. I just compiled the same code in VS 2005 and got a 24 KB executable. Looks like the VS 2008 compiler's a lot more efficient.
This is good news.
Thanks very much, AtmaWeapon.
Reply With Quote
  #13  
Old 04-17-2008, 05:23 PM
darkforcesjedi's Avatar
darkforcesjediProcess of Compiling VB.Net Source Code darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

All executables contain a tremendous amount of redundant data. Drop an executable from any platform, created in any language into WinZip and the executable code will compress substatially. (Binary data and resources in the EXE won't necessarily compress as much).

There are utilities and some compilers that compress your executable and decompress it into memory at run-time ( http://upx.sourceforge.net/ ). This can dramatically reduce file sizes for distribution without requiring the target user to have a decompression utility.
__________________
To err is human; to debug, divine.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
 
Process of Compiling VB.Net Source Code
Process of Compiling VB.Net Source Code
 
-->