views:

51

answers:

4

VB.NET: Can the .EXE built by VS2005 be deployed as a standalone EXE?

When I change the mode in VS2005 to "Release" and build the solution, the bin\Release directory then contains the solution .EXE file, but also a .pdb, vshost.exe and .xml file. What are these extra files and are they necessary?

I copied the .exe file to another machine and it executed properly, but there was a significant delay when it first executed - thereafter it was like any other program. What is the reason for this, and can it be helped? Is it because the other 3 files in the Release folder are not there with it?

A: 

Only .Exe file is required for deployment. But its better to create a setup. If you are using App.Config file / Application settings, you need to copy the exename.config file too.

Anuraj
@Anuraj: what will happen if the incorrect .NET framework is installed or the .NET framework is not installed at all?
Craig Johnston
@Craig Johnston: If you are creating a Setup there will be prerequisites, so the setup will check for .Net Framework, or any other dependencies.
Anuraj
+2  A: 

You should be able to just ship the EXE. The PDB and VSHOST files are used for debugging, you should be able to configure your Release build to not generate these files. You can set this in the 'Advanced Compiler Settings' dialog from the Compile tab in your project properties. alt text (Hat-tip to Amissisco for pointing out it's the same dialog in VS2005/2008.)

I'd imagine the 'significant delay' you experienced when running the program for the first time was due to the .NET Framework being loaded into memory (and probably then paged back out to disk) - unfortunately there's not much getting round that one. You could try throwing hardware at it - memory and a solid-state disk would probably give an appreciable speed increase but may not be a cost-effective option if your application is going to be released on a significant number of PCs. However this should only take place the first time you fire up the application after a machine restart, which is why subsequent launches of your application are quicker.

PhilPursglove
VS2008 has same configuration.
AMissico
@Phil: how often does the .NET framework need to be loaded into memory? Once per Windows session?
Craig Johnston
@Craig - yep, updated my answer.
PhilPursglove
@Phil: could the .NET framework be loaded by another app starting and thereby cause the first run of other .NET apps to be quicker, or will there be this delay for the first run of every .NET app?
Craig Johnston
@Craig Yes - the framework itself should only need to be loaded once per session.
PhilPursglove
A: 

Yes, you can deploy it as a standalone EXE, together with any third party DLLs that do not belong to the .NET Framework as well as other resources such as application.config. images and/or other media assets.

The .pdb contains additional symbolic debug info which is not necessary for your application to run. It's meant to assist debugging so that you see your source code instead of assembly code in the debugger.

vshost.exe is used by Visual Studio only, not too sure about the exact purpose of it though.

Whether these three files (.pdb, vshost.exe and the .xml) are present with the .exe should not affect the loading speed of your application. As .NET applications have to be compiled upon first run, the delay that you're experiencing should be partially due to that.

Mr Roys
@Roys: is there any way to speed up the first run, because I find it particularly slow and unacceptable if I am deploying a small utility or tool.
Craig Johnston
Well, there are two articles by Claudio Caldato at MSDN Magazine @ http://msdn.microsoft.com/en-us/magazine/cc163655.aspx and http://msdn.microsoft.com/en-us/magazine/cc337892.aspx. Have to confess that I've never tried to optimize the startup time of my .NET apps before - used a splash screen to denote that the application was loading.
Mr Roys
@roys: I wouldn't normally care about a short delay at startup but when it is just a very small tool or utility then I think the delay is unacceptable.
Craig Johnston
See the tips in the first article then. While it's written back in 2006, things like avoiding unnecessary initialization and loading fewer modules at startup should still be applicable. NGEN is also mentioned, but I haven't tried that out.
Mr Roys
+2  A: 

The project template that you used to get the project started doesn't have very optimum settings. You'll get the clutter as a result. It is easily fixable. Start with Project + Properties, Compile tab. Make sure the Release build is selected, upper left combo box labeled Configuration.

  • The .pdb file contains debugging symbols. You don't need it for the Release build although you get slightly more informative exception messages. The stack trace will contain line numbers. You cannot trust them for a Release build though. Click Advanced Compile Options, Generate debug info = None.

  • The .xml file contains IntelliSense info, it will be generated when you use XML Documentation in your source code. Meant to be used for assemblies that are referenced in another project, quite pointless for an EXE project. Turn off the "Generate XML documentation file" option on the Compile tab.

  • The .vshost.exe file is a helper process for debugging your app. It hosts a custom version of CLR, configured differently to help with security issues while debugging. It also makes the output of Console.WriteLine() appear in the Visual Studio Output window. There's little point in having it created for the Release build. Select the Debug tab and uncheck the "Enable the Visual Studio hosting process" option.

After making these changes and rebuilding, you should only have the .exe file left in the bin\Release folder.

The slow startup is what's called a "cold start" of the .NET framework assemblies. It is caused by a slow or fragmented hard drive. Since the DLLs were never loaded before, the disk drive needs to dig through the GAC to find the files. You can probably improve it by defragging the disk. Cold starts are never as fast as warm starts though.

A classic trick, used by Microsoft Office and Adobe Acrobat, is to warm up the file system cache by loading their DLLs at login time. They are called "optimizer" in the Startup folder or Run registry key. Very annoying btw, they slow down other programs. You can do the same thing by writing your own little .NET program that doesn't do anything but create a few classes. Put a shortcut to it in the Startup folder.

Hans Passant
@hans: how do I speed up the first run of a .NET executable?
Craig Johnston
@craig: post updated.
Hans Passant
@hans: but my .net app is very small. It just reads in a text file, makes a change and then writes back to the file. It wouldn't need many .net classes to be loaded. Would NGEN help?
Craig Johnston
Your app is small but .NET is not. Yes, ngen can help with warm start time, it has little effect on cold start time though. Using ngen for small apps is not recommended. Ask at superuser.com about ways to improve cold starts, you don't sound convinced that this is a hard disk problem.
Hans Passant