How to automate the install of the .NET Framework 3.0 OS component on Windows Vista and Windows Server 2008

Windows Vista and Windows Server 2008 include the .NET Framework 2.0 and 3.0 as OS components.  However, it is possible to turn off the .NET Framework 3.0 component on both of these operating systems so it is not available for applications to use.  In addition, the .NET Framework 3.0 is not installed by default on Windows Server 2008.

How the .NET Framework 3.5 setup.exe handles the .NET Framework 3.0 component

The .NET Framework 3.5 requires the .NET Framework 3.0 as a prerequisite, and the ability to turn off the .NET Framework 3.0 on Windows Vista and Windows Server 2008 can complicate the steps required to deploy the .NET Framework 3.5 on these operating systems.

There is logic within the setup.exe wrapper for the .NET Framework 3.5 to add the .NET Framework 3.0 OS component on Windows Vista and Windows Server 2008 if it is not currently present on the system.  This ensures that you cannot install the .NET Framework 3.5 without first satisfying the .NET Framework 3.0 prerequisite when installing using the setup.exe wrapper.

What happens if you install the .NET Framework 3.5 without 3.0

However, if you are using the instructions in the .NET Framework 3.5 Administrator Deployment Guide to create an administrative install point and then deploying the .NET Framework 3.5 MSI directly, you will see the .NET Framework 3.5 MSI install successfully even if the .NET Framework 3.0 OS component is not present on the system.  There is a blocking custom action within the MSI that is designed to enforce this prerequisite, but it is incorrectly conditioned to not run on Windows Vista or higher.

To make matters worse, if you install the .NET Framework 3.5 MSI on a Windows Vista or Windows Server 2008 system that does not have the .NET Framework 3.0 OS component installed, you will likely encounter exceptions while trying to run applications that depend on the .NET Framework (for example - the ServerManagerCmd tool or the MMC snap-in host).  When a system is in this state, you cannot go to the Programs and Features control panel to add the .NET Framework 3.0 OS component because the Windows Features control panel is hosted by the MMC snap-in host.

If you end up with a system in this state, you will have to run a command line (listed below) to add the .NET Framework 3.0 OS component, or remove the .NET Framework 3.5 using the Programs and Features control panel, add the .NET Framework 3.0 OS component and then re-install the .NET Framework 3.5.

How to install the .NET Framework 3.0 OS component in a deployment scenario

For .NET Framework 3.5 deployment scenarios on Windows Vista and Windows Server 2008 that involve installing the 3.5 MSI directly, I recommend that you add logic to your deployment process to check for the existence of the .NET Framework 3.0 OS component, and trigger the install of this OS component if it is not present.  You can use the following registry value to determine whether or not the .NET Framework 3.0 OS component is installed:

[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup]
InstallSuccess=1

If the .NET Framework 3.0 OS component is not installed, the following command line can be used to trigger an install of this component on Windows Vista and Windows Server 2008:

%windir%\system32\OCSetup.exe NetFx3 /quiet /norestart

The above registry value is the same one used by the setup.exe wrapper for the .NET Framework 3.5 and the same one used in the sample code for .NET Framework detection that I have previously published (which is based on the official .NET Framework 3.0 deployment guide).  In addition, the above install command line is the same one used by the setup.exe wrapper for the .NET Framework 3.5 to add the .NET Framework 3.0 OS component on Windows Vista and Windows Server 2008 systems that it is not currently installed on.

A note about ServerManagerCmd

In addition to the above registry value, there is a tool that ships with Windows Server 2008 named ServerManagerCmd that can be used to query the installed state of OS components such as the .NET Framework 3.0.  Some information about how to use this tool can be found in the Overview of Server Manager Commands topic on TechNet.  When using the -query flag, you will get output like the following snippet on a system that has the .NET Framework 3.0 OS component installed:

2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]          ----- Features -----
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]         
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]          [X] .NET Framework 3.0 Features  [NET-Framework]
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]              [X] .NET Framework 3.0  [NET-Framework-Core]
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]              [ ] XPS Viewer  [NET-XPS-Viewer]
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]              [ ] WCF Activation  [NET-Win-CFAC]
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]                  [ ] HTTP Activation  [NET-HTTP-Activation]
2196: 2008-03-25 11:11:11.111 [ServerManagerCmd]                  [ ] Non-HTTP Activation  [NET-Non-HTTP-Activ]

Note that there are several sub-components listed under the .NET Framework 3.0 feature in this example output.  You do not need the XPS Viewer or WCF Activation features enabled in order to be able to successfully use the .NET Framework 3.0 or install the .NET Framework 3.5.