Building a project that target .NET Framework 4.5 in Visual Studio 2022
source link: https://thomaslevesque.com/2021/11/12/building-a-project-that-target-net-45-in-visual-studio-2022/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Building a project that target .NET Framework 4.5 in Visual Studio 2022
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!
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!
Recommend
-
6
How to create a Visual Studio extensibility project that is compatible with VS 20...
-
10
C#与.NET Framework 和 Visual Studio 之间的版本对应关系DevWikiC#与.NET Framework 和 Visual Studio 之间的版本对应关系
-
10
Project System Tools for MonoDevelop and Visual Studio for Mac Inspired by Project System Tools for Visual Studio on Windows. Build Logging Window To open t...
-
10
How to add a reference to the C ++ project in Visual Studio? advertisements In C# it's pretty simple to add a project reference that will buil...
-
19
Visual Studio Code project manager using Alfred workflowPublished: 2021.03.26 | 1 minutes readI spend a lot of time using Visual Studio Code, jumping from one project to another. To make it more efficient, I would love to have...
-
9
Description Andrew Clinick shows us Project Reunion, which is the starting point for your ability to build and ship Windows apps at a much faster pace without waiting for the Windows OS to update with new features.
-
3
.NET News Roundup: Microsoft Build, .NET 6, MAUI, Visual Studio 2019, Project Reunion May 31, 2021...
-
5
.NET News Roundup: Visual Studio 2019 for Mac, Windows ML, Project Tye, Oqtane Jun 07, 2021...
-
6
Visual Studio 2022 升级不再附带 .NET Framework 4.5 这种古老的目标包了,本文帮你装回来 2021-11-09 01:58 就在北京时间 2021 年 11 月 9 日凌晨,Visual...
-
13
无需安装 VS2019,在 Visual Studio 2022 中编译 .NET Framework 4.5/4/3.5 这样的古老框架 2021-11-11 09:59 Visual Studio 2022 已正式发布!着急升级的小...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK