Skip to content

Working with .NET Framework 4.5 in Visual Studio 2022

When upgrading to Visual Studio 2022, developers often encounter issues opening projects targeting older .NET Framework versions like 4.5. This guide covers the best approaches to resolve this compatibility problem.

Problem Overview

Visual Studio 2022 doesn't include .NET Framework 4.5 targeting packs by default since this version reached end-of-support in January 2016. Attempting to open such projects results in errors indicating the target framework is unavailable.

WARNING

.NET Framework 4.5 reached end of support on January 12, 2016. Consider upgrading to a supported framework version if possible.

Option 1: NuGet Package Reference (Preferred Approach)

The cleanest solution is adding a reference to the Microsoft reference assemblies package directly in your project file:

xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net45</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Advantages:

  • No administrative privileges required
  • Works on build servers without Visual Studio
  • Automatically handles reference assembly provisioning
  • The PrivateAssets="all" setting ensures it's a design-time only dependency

Option 2: Download Developer Pack from Microsoft

For scenarios where you need the full targeting pack installed:

  1. Visit the Microsoft Developer Packs page
  2. Expand the "Out of support versions" section
  3. Download the .NET Framework 4.5.2 Developer Pack

INFO

While .NET Framework 4.5 itself isn't available, 4.5.2 is backward compatible and may resolve your compatibility issues.

Option 3: Install via Windows SDK

The Windows 8 SDK includes the .NET Framework 4.5 Software Development Kit:

  1. Download the Windows 8 SDK
  2. During installation, select only ".NET Framework 4.5 Software Development Kit"
  3. Complete the installation process

This approach installs the necessary components without additional Visual Studio editions.

Alternative Approaches

Manual Reference Assembly Installation

If you prefer manual installation:

powershell
# Download the NuGet package
$url = "https://www.nuget.org/api/v2/package/Microsoft.NETFramework.ReferenceAssemblies.net45"
$outputZip = "$env:TEMP\net45_reference_assemblies.zip"

# Download and extract
Invoke-WebRequest -Uri $url -OutFile $outputZip
Expand-Archive -Path $outputZip -DestinationPath "$env:TEMP\net45" -Force

# Copy to reference assemblies directory (requires admin)
Copy-Item -Path "$env:TEMP\net45\build\.NETFramework\v4.5\*" `
          -Destination "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\" `
          -Recurse -Force

Install Visual Studio 2019 Side-by-Side

Visual Studio 2019 includes .NET Framework 4.5 targeting support:

  1. Install Visual Studio 2019
  2. During installation, select ".NET Framework 4.5 targeting pack" in Individual Components
  3. Keep both Visual Studio versions installed

DANGER

Uninstalling Visual Studio 2019 may remove the targeting packs. Backup the reference assemblies directory if you plan to uninstall.

Troubleshooting Tips

If you continue to experience issues:

  1. Clean solution artifacts: Delete bin, obj, and .vs folders
  2. Restore packages: Run dotnet restore from the command line
  3. Restart Visual Studio: After making any changes
  4. Check framework installation: Ensure the .NET Framework runtime is installed for testing
Available .NET Framework Reference Assemblies
VersionStatusNuGet Package
.NET 4.8SupportedMicrosoft.NETFramework.ReferenceAssemblies.net48
.NET 4.7.2SupportedMicrosoft.NETFramework.ReferenceAssemblies.net472
.NET 4.5Out of supportMicrosoft.NETFramework.ReferenceAssemblies.net45
.NET 4.0Out of supportMicrosoft.NETFramework.ReferenceAssemblies.net40

Best Practices

  1. Upgrade when possible: Migrate to a supported .NET Framework version (4.6.1 or later) or .NET 6+
  2. Use SDK-style projects: Convert legacy projects to the modern SDK format
  3. Document dependencies: Clearly reference framework requirements in your project files
  4. CI/CD configuration: Ensure build servers have the necessary targeting packs or reference assemblies

Conclusion

While Visual Studio 2022 doesn't include .NET Framework 4.5 targeting packs by default, multiple workarounds exist. The NuGet reference assembly approach is recommended for most scenarios as it requires no elevated permissions and works across development and build environments. For legacy maintenance projects, installing the developer pack or using Visual Studio 2019 alongside VS2022 provides alternative solutions.

Remember that .NET Framework 4.5 is unsupported, and upgrading to a currently maintained framework version should be prioritized for security and compatibility reasons.