At this time, I’m still in the middle point between C++ native applications and C# .net applications. After spending times to develop a C++/CLI .net application using visual studio express, I found out how hard it is to deploy the finished program to other computers. I’ll share my findings and solutions below.

Two requirements for getting a .net program developed with visual studio to run on a separate computer are the .NET Framework and the Visual C++ Libraries. More importantly, both have to be the right versions.

If you transfer the compiled exe application to a computer without these two components, you’ll get runtime errors such as “The application failed to initialize properly (0xc0000135)” or “This application has failed to start because the application configuration is incorrect. Reinstalling application may fix this problem”.

First of all, the important dependency that the user should worry about is the visual c++ libraries package. Most Windows XP computers with SP2 should have at least .NET framework 2.0 installed and all Windows Vista already have .NET framework 3.0. And .NET framework should be listed as optional install in lower windows versions. However, you’ll still have to check to see if the targeted pc already have .net framework installed. You can accomplish this by creating an installer with a check for the existence of .net framework and ask the user to install the .NET framework Redistributable Package from Microsoft’s download site or windows update if it does not exist (if you use the NSIS, here’s an example). Make sure to request the user to install the version that matches the finished .net application. (.net 2.0 applications can still run in .net 3.0 framework).

The other dependency, visual c++ libraries, is another problem if the targeted computer does not have visual studio installed. There are several ways to solve this:

1. Non-express edition only: use a Setup project template to create the msi installer with merge modules. See the MSDN pagefor more info on that. The msi installer will install vc++ library dlls as shared side-by-side assemblies.

2. Distribute vc++ library dlls via Visual C++ Redistributable Package (vcredist_*.exe) from Microsoft downloads . This method will also depoly visual c++ library dlls as shared side-by-side assemblies into the WinSxS folder. Be careful though, the user must install the right version for the application to run. A program developed with VC++ SP1 will not run with the VC++ redistributable package without the SP1. The dll’s in the redistributable package with and without the SP1 are not the same. For non-express version, the vcredist_*.exe be found in \program files\microsoft visual studio 8\SDK\v2.0\Bootstrapper\Packages\. A custom installer may be created to install the redistributable package before installing the application.

3. VC++ library dlls can also be distributed as private assemblies. The benefit of this is that the user does not have to install the package into the native assembly cache, or the WinSxs folder, and the program will run using the dlls placed in the same folder.

For non-express edition, copy Microsoft.VC80.CRT folder (also MFC folder if that’s used in the development) from c:\program files\microsoft visual studio 8\VC\Redist\x86 to the same place as the application.

For visual studio 2005 express, you need to use the method suggested by Ted on msdn forum. I’ll briefly state it with a few addons: create a folder called Microsoft.VC80.CRT in the same place as where the application is. Copy the dlls from c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.762_none_10b2f55f9bffb8f8 (Now that’s the folder name I have, yours will be different; choose the folder with the highest version (8.0.50727.***) ) to the Microsoft.VC80.CRT folder. Create a manifest file (see the forum for an example) in the Microsoft.VC80.CRT folder with the correct versions.

For visual studio 2008 express (beta version right now), it seems the team made improvements and you don’t have to go through the winsxs folder to copy all the dlls and create the manifest file. Just copy the folder C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT straight to where the application is.

4. Building a CRT windows installer from merge modules using WiX for vc++ express as described by Nikola Dudar.

5. Compile the program with statically linked libraries. More on this as well by Dudar.

Deploying .NET applications built with VC++ express is confusing at first and took me awhile to get everything straight. But now after searching for methods at various places, I listed all my findings here. I’ll update this list as I discover/find more solutions.