How to: Deploy a Setup and Deployment Project

This topic focuses on a Setup and Deployment Project project type. For background on this deployment scenario, see Scenarios for Deployment Examples.

Procedures for deploying Visual C++ library DLLs as shared assemblies

Create a Setup and Deployment Project

  • From the File menu, click New Project, open the Other Project Types node and select Setup and Deployment, and then click Setup Project. Supply a name and click OK.

    Note

    Visual C++ Express does not support Setup Projects. To redistribute Visual C++ libraries with applications built in Visual C++ Express, use the Visual C++ Redistributable Package. Please see How to: Deploy using XCopy for more information.

Add the EXE and DLL to the project and specify where they should be installed on the target computer

  1. From the Project menu, select Add and click File.

  2. Find the folder that contains MyApplication.exe and MyLibrary.DLL and select them both.

  3. In the File System window, right-click on Application Folder, point to Add and click Create to create a new folder. Call it MyLibrary.

  4. Click on Application Folder again, select MyLibrary.DLL and drag it to the MyLibrary folder.In Solution Explorer, under your project in Detect Dependencies you should see that the Visual Studio detects dependencies on MFC90.dll and MSVCR90.dll. You must add the corresponding Merge Modules for these DLLs.

  5. From the Project menu, point to Add and click Merge Module. Select Microsoft_VC90_CRT_x86.msm and Microsoft_VC90_MFC_x86.msm, and click OK. For the debug versions of these merge modules, select Microsoft_VC90_DebugCRT_x86.msm and Microsoft_VC90_DebugMFC_x86.msm.

    Note

    Verify that the corresponding policy*.msm modules are incorporated into your project. For example, policy_9_0_microsoft_vc90_crt_x86.msm and policy_9_0_microsoft_vc90_mfc_x86.msm correspond to Microsoft_VC90_CRT_x86.msm and Microsoft_VC90_MFC_x86.msm, respectively. Visual Studio will detect that the main modules depend on these policy modules and list them under Detected Dependencies. If the dependencies are not detected automatically, you will have to manually merge the policy modules.

    For deploying 64-bit applications to a 64-bit operating system, select the merge module for the corresponding platform. For x64, select Microsoft_VC90_CRT_x86_x64.msm and Microsoft_VC90_MFC_x86_x64.msm; for Itanium, Microsoft_VC90_CRT_x86_ia64.msm and Microsoft_VC90_MFC_x86_ia64.msm.

Build setup.exe

  • Click Build Solution from the Build menu.

Run setup.exe

  1. Now if you take the setup.exe you just built and run it on an operating system that supports manifest-based binding of applications to their dependencies (Windows XP Home Edition, Windows XP Professional, Windows Server 2003), the following things occur:

  2. Your application is installed in the specified target folder.

  3. Merge modules install the CRT and MFC assemblies as shared side-by-side assemblies. You can verify this by checking folders %WINDIR%\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_8.0.50613.12800_x-ww_b7acac55\ and %WINDIR%\WinSxS\x86_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_8.0.50613.12800_x-ww_88931f5a\

  4. The application and DLL use the CRT and MFC assemblies at runtime. You must add %TARGET%\MyLibrary to the PATH environment variable so that MyApplication.exe can find Mylibrary.Dll. (Or you could rebuild it as a side-by-side assembly.)

    On an operating system that does not support manifest-based binding (Windows 2000), this is what occurs:

  5. Your application is installed in the specified target folder.

  6. Merge modules install the CRT and MFC assemblies in two locations:

    • %WINDIR%\System32—This guarantees that applications run on this operating system even though it does not support manifest-based binding.

    • %WINDIR%\WinSxS (similar to Windows XP Home Edition, Windows XP Professional, Windows Server 2003)—This guarantees that when the operating system is upgraded to Windows XP Home Edition, Windows XP Professional, Windows Server 2003, your application will still run and start to use the DLLs in WinSxS. The DLLs in System32 will be removed in the process by which Windows Upgrade informs already-installed applications about operating system upgrades.

  7. The application and DLL use the CRT and MFC DLLs from System32 at runtime.

Procedures for deploying Visual C++ library DLLs as private assemblies

Create a Setup and Deployment Project

  • From the File menu, click New Project, open the Other Project Types node and select Setup and Deployment, and then click Setup Project. Specify a name and click OK.

Add EXE and DLL to the project and specify where they should be installed on the target computer

  1. From the Project menu, select Add and click File.

  2. Find the folder that contains MyApplication.exe and MyLibrary.DLL and select them both.

  3. In the File System window, right-click Application Folder, point to Add and click Create to create a new folder. Call it MyLibrary.

  4. Click Application Folder again, select MyLibrary.DLL and drag it to the MyLibrary folder.In Solution Explorer, under your project in Detect Dependencies you should see that Visual Studio detects dependencies on MFC90.dll and MSVCR90.dll. You must add a corresponding folder for these assemblies from the \vc\redist folder.

    Note

    For debug builds, use \vc\redist\debug_nonredist.

  5. Open %PROGDIR%\Microsoft Visual Studio 8\VC\Redist\x86 in Windows Explorer.

  6. Holding the Ctrl key, click the folders Microsoft.VC90.CRT and Microsoft.VC90.MFC. Drag these folders to Visual Studio and drop them into the Application folder.

  7. Repeat step 6, but this time drag the folders to the MyLibrary folder.

    You may see a message from Visual Studio that says that you are including a DLL that is part of a Merge Module. This is exactly what you want to do. Therefore, click No to indicate that you do not want to use an MSM for this DLL.

    You need mfcm90.dll and its Unicode version mfcm90u.dll only if you use MFC/Windows Forms integration. Otherwise you can remove these DLLs from your setup.

    You need msvcm90.dll only if you are using managed code in your applications, for example, if your projects are built with /clr or /clr:pure.

    If mfcm90.dll, mfcm90u.dll, or msvcm90.dll is included in the setup project, an installation of the .NET Framework is required. Your setup will not work without .NET Framework 2.0 installed on the target machine.

    For debug installation, change CRT to DebugCRT and MFC to DebugMFC in the previous step.

    For deploying 64-bit applications to 64-bit operating systems, use \vc\redist\amd64 or \vc\redist\ia64.

Build setup.exe

  • Click Build Solution from the Build menu.

Run setup.exe

  1. Now if you take the setup.exe you just built and run it on an operating system that supports manifest-based binding (Windows XP Home Edition, Windows XP Professional, Windows Server 2003), the following things occur:

    • Your application is installed in the specified target folder.

    • The application and DLL use the CRT and MFC assemblies from the Microsoft.VC90.CRT and Microsoft.VC90.MFC folders at runtime.

  2. On an operating system that does not support manifest-based binding (Windows 2000), this deployment method is not recommended. If you try to deploy Visual Studio assemblies as private assemblies on these operating systems following the steps described earlier, the operating system loader will be unable to locate the CRT and MFC DLLs. The folders that contain Microsoft.VC90.CRT and Microsoft.VC90.MFC must be added to the PATH environment variable for the loader to locate them. Under this mode, the following things occur:

    • Your application is installed in the specified target folder.

    • The system loader will resolve the location of the CRT and MFC private assemblies from the Microsoft.VC90.CRT and Microsoft.VC90.MFC folders through the PATH environment variable at runtime.

See Also

Tasks

How to: Deploy using XCopy

Concepts

Deployment Examples