Q: How do I add the .NET Framework 3.5 to my VHD or WIM file so it's locally available should I want to enable it in the future?

A: As you might know, in Windows Server 2012 and Windows 8 the .NET Framework 3.5 isn't locally available for installations. This is because of its size and because Windows 2012/Windows 8 have the new .NET Framework 4.0, so providing both used too much disk space.Instead, when .NET Framework 3.5 is enabled as a feature, it's either downloaded from Windows Update or you can specify a location such as a folder or WIM file as the source.

The easiest way to add the .NET Framework 3.5 to a (virtual hard disk) VHD file (that's perhaps a template for the creation of future virtual machines--VMs) is to just add the .NET Framework 3.5 feature, which will cause the files to be copied to the VHD; then disable the .NET 3.5 feature (which will leave the files locally available).

Run the Add Roles and Features Wizard as usual, but select the option to select a VHD from the Server Selection page, pick your VHD, then continue. After .NET Framework 3.5 is added, rerun the wizard in removal mode, select the same VHD, and remove the feature.

The screenshots below show the entire process. This could also be done with Windows PowerShell by using the Install-WindowsFeature and Remove-WindowsFeature cmdlets.

net35add1sml
Add Roles and Features Wizard

net35add2sml
Selecting Features in Add Roles and Features Wizard

net35add3sml
Installation Progress

net35add4sml
Removing .NET Framework

For a WIM file, using DISM is the best choice. In the example below, I mount the WIM file, then add .NET Framework 3.5 with the source being my local server's side-by-side assembly (which already has .NET Framework 3.5 installed using Features on Demand). Then I remove it straight away (which leaves the files in the WIM). Once it's removed, dismount the WIM by usingĀ  the commit option.

 

PS D:\> dism /Mount-Wim /wimfile:d:\sources\install.wim /index:4 /mountdir:d:\temp\wimmount



Deployment Image Servicing and Management tool

Version: 6.2.9200.16384


Mounting image

The operation completed successfully.


PS D:\> dism /image:d:\temp\wimmount /enable-feature /featurename:NetFx3 /All /Source:c:\windows\winsxs


Deployment Image Servicing and Management tool

Version: 6.2.9200.16384


Image Version: 6.2.9200.16384


Enabling feature(s)

The operation completed successfully.
PS D:\> dism /image:d:\temp\wimmount /disable-feature /featurename:NetFx3



Deployment Image Servicing and Management tool

Version: 6.2.9200.16384


Image Version: 6.2.9200.16384


Disabling feature(s)

The operation completed successfully.

 

PS D:\> dism /Unmount-Wim /mountdir:d:\temp\wimmount /commit
 

Deployment Image Servicing and Management tool

Version: 6.2.9200.16384


Image File : d:\sources\install.wim

Image Index : 4

Saving image
Unmounting image

The operation completed successfully.