Add .net Framework to Visual Studio 2022

Introduction 

You might have noticed that some of the legacy projects (.NET 4.5 framework) are no longer supported in Visual Studio 2022 directly. We will get some errors while opening those projects.  

Because Microsoft is no longer supplying the developer pack (SDK) for .NET framework 4.5 or lower versions now.  

Add .net Framework to Visual Studio 2022

If you are trying to open a legacy .NET 4.5 framework project in Visual Studio 2022, you will get the below warning messages.  

Add .net Framework to Visual Studio 2022

You can update the target to .NET framework 4.8 but it may affect the other people who are still working on the same project with older version of Visual Studio. Also, sometimes it will not work even after you updated the target to 4.8 framework.  

But we can download the .NET 4.5 framework in another way. We can download the reference assemblies from the NuGet library given below. 

Microsoft.NETFramework.ReferenceAssemblies.net45 

Add .net Framework to Visual Studio 2022

After downloading this package file, you must use any of the file extracting applications to extract above package. Some of the applications like 7-zip support to extract NuGet packages. 

7-zip is an open source and free software tool. 

https://www.7-zip.org/ 

After extracting the package, under build -> .NETFramework folder you can find a v4.5 folder.  

Downloads\microsoft.netframework.referenceassemblies.net45.1.0.2\build\.NETFramework\v4.5 

You can copy the entire files from this v4.5 folder and paste under the folder below in your machine. 

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5 

Above is the current .NET framework 4.5 version folder.  

Add .net Framework to Visual Studio 2022

There are 309 files in the NuGet package folder, and it will replace the existing 120 files in our current .NET 4.5 framework folder.  

After replacing the files, we can try to open the legacy project in Visual Studio 2022. 

Project will be opened without any issues.  

On some occasions, if you face any error like below you can clean the solution and build again. 

After cleaning and rebuilding the solution, the application will work without any issues.  

I am giving credits for this post to Thomas Levesque and his post below. 

https://thomaslevesque.com/2021/11/12/building-a-project-that-target-net-45-in-visual-studio-2022/

Conclusion 

In this post, we have seen the simple steps to open legacy .NET 4.5 projects in latest Visual Studio 2022. I have attached one legacy application with this post. You can try to open this project in your machine and follow the steps mentioned in the post. If you are still facing some other issues while opening legacy projects in Visual Studio 2022, please feel free to message me here.

I maintain a few libraries that still target .NET Framework 4.5 (among others). .NET 4.5 has long been out of support, but I try to keep supporting older frameworks in my libraries as long as it’s not a major inconvenience, because many people maintain old applications that can’t easily be updated to a newer framework.

Anyway, until recently, supporting .NET 4.5 wasn’t much of a problem, but today I hit a snag… Before installing VS 2022 on my Surface Pro, I removed VS 2019 and old versions of .NET (I don’t have much space on this machine!). Then, when I tried to build one of my libraries in VS 2022, I started getting this error:

error MSB3644: The reference assemblies for framework “.NETFramework,Version=v4.5” were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed

Strangely, building from the command line with dotnet build still works fine.

OK, fine, I’ll just install the targeting pack for .NET 4.5 from this page… Except it isn’t there!

Add .net Framework to Visual Studio 2022

For some reason, the oldest version of .NET Framework for which a developer pack is available is 4.5.1. I could just retarget my libraries to .NET Framework 4.5.1, but it’s annoying…

Fortunately, there’s an easy solution! And it has something to do with why it still works with dotnet build… Visual Studio and the .NET CLI actually use a slightly different version of MSBuild. The one used by Visual Studio looks for .NET Framework reference assemblies in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5, which doesn’t exist on my machine. The one used by dotnet build, on the other hand, gets the reference assemblies from a NuGet package: Microsoft.NETFramework.ReferenceAssemblies.net45.

So, the fix is simple: just copy the files from that package to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5! Just download the package from NuGet, open it as a zip, and copy the files from build\.NETFramework\v4.5\.

And that’s it! Visual Studio can now build projects that target .NET Framework 4.5. I hope this helps someone, because I couldn’t find any useful information about this on the web!

How to install net Framework in VS 2022?

From the developer pack download page, choose Download. Next, choose Run or Save, and follow the instructions when prompted. You can also install the developer pack or targeting pack for a specific version of . NET Framework by selecting it from the optional components in the .

Does Visual Studio 2022 support .NET framework?

Starting with Visual Studio 2022, Visual Studio no longer includes . NET Framework components for . NET Framework 4.0 - 4.5. 1 because these versions are no longer supported.

How to add net Framework 5 in Visual Studio 2022?

3 Answers.
Open Visual studio installer from start menu..
Select Modify from Visual Studio that you want to add..
in individual components select .net core or framework that you want to add to your visual studio version..

How to install .NET Framework 4.5 in VS 2022?

So, the fix is simple: just copy the files from that package to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4. 5 ! Just download the package from NuGet, open it as a zip, and copy the files from build\.