19

I have recently upgraded my Visual Studio environment, and now I seem to have a problem with my .Net framework, as you can see in following error message:

9> C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): 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. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

(the number "9" is just a counter of the nineth project within my Visual Studio solution)

Let me explain you what's so confusing about this situation:

When I load my solution, I get following error message:

The C# project ... is targeting ".NETFramework,Version=4.5", which is not installed on this machine. To proceed, select an option below:

  • Change the target to .NET Framework 4.6.1. You can change back to ".NETFramework,Version=4.5" at a later time.
  • Download the targeting pack for ".NETFramework,Version=4.5". The project will not change.
  • Do not load the project.

I choose for the second option, and I get following website: .NET SDKs for Visual Studio

This gives the following: list of .NET Frameworks:

4.7.1   Developer Pack, included in Visual Studio 2017   Runtime   Release Details
4.7     Developer Pack, included in Visual Studio 2017   Runtime   Release Details
4.6.2   Developer Pack, included in Visual Studio 2017   Runtime   Release Details
4.6.1   Developer Pack, included in Visual Studio 2017   Runtime   Release Details
4.6     Developer Pack, included in Visual Studio 2017   Runtime   Release Details
4.5.2   Developer Pack, included in Visual Studio 2017   Runtime   Release Details
3.5 SP1 Developer Pack, included in Visual Studio 2017   Runtime   Release Details

=> Where is 4.5?
I have already different times downloaded 4.5.2 version, Developer Pack as well as Runtime, but nothing changes.

So, after a while, I just close the dialog box about the missing target. I'm expecting to get a more readable error message, once I get to the compilation of the project.

Next to that, I've also investigated the installation of my PC (PC settings, Add and Remove Programs), this gives following list:

Microsoft .NET Core SDK - 2.1.4 (x64)
Microsoft .NET Framework 4.5 SDK
Microsoft .NET Framework 4.5.1 Multi-Targeting Pack (ENU)
Microsoft .NET Framework 4.5.1 SDK
Microsoft .NET Framework 4.5.2 Multi-Targeting Pack (ENU)
Microsoft .NET Framework 4.6 Targeting Pack
Microsoft .NET Framework 4.6.2 SDK
Microsoft .NET Framework 4.6.2 Targeting Pack
Microsoft .NET Framework 4.7 SDK
Microsoft .NET Framework 4.7 Targeting Pack

=> Ok, there seems not to be a targeting pack for 4.5 (only the SDK seems to be present), but what to do about it?

The error message speaks about retargeting my application, but that's out of the question: I'm the only person, having this problem, and modifying the configuration of a central application is not a solution.

The error message also speaks about the so-called "Global Assembly Cache" which will be used in place of reference assemblies. So, let's have a look at those things:

I seem to have two reference assemblies on my PC:

C:\Program Files\Reference Assemblies\Microsoft\Framework (seems only to contain "v3.0" and "v3.5" directories)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.

The latter seems to contain a ".NETFramework" directory, which, at his turn, contains a "v4.5" subdirectory, containing quite some XML files.

The error message however states that those are not used, the "Global Assembly Cache (GAC)" is used instead. If I try finding this, I find references to gacutil, sn -k ... and other programs which are not found on my PC for the specied .Net framework.

If I look, using Google, for "Microsoft .Net Framework 4.5 Targeting Pack" (exact phrase), I get zero results.

So, in other words, I get a message about a missing piece of software on my PC. I get the opportunity to install it but the installation does nothing. Then I get a compilation error about this, which talks about a very general technology which seems not to exist following Google, the mostly used search engine on the internet. It mentions a technology (GAC) which might be used or not and who is found, either on C:\Program Files or C:\Program Files (x86), and its corresponding tool (gacutil) seems only to exist on my PC for other versions.

Can anybody give me a push in the right direction here?
Thanks in advance

2
  • The Reference Assemblies subdirectory should not just contain .xml files. How the DLLs there got deleted is impossible to guess, other than that 4.5 has been out of support for a long time. You'll have to spin the repair/reinstall wheel of fortune. Changing the framework target to 4.5.2 or higher is an obvious workaround. Mar 20, 2018 at 11:45
  • I am very new to C# and vscode. I have Two projects Unity and HelloWorld and there is a vscode setting "use Modern net" checked or unchecked. if checked, the Unity projects are with errors but HelloWorld are free of errors; if unchecked, the HelloWorld projects are with errors but Unity projects are free of errors..
    – X.C.
    Dec 15, 2022 at 17:02

5 Answers 5

16

Meanwhile I've solved the issue, and it comes down to a general truth in working with computers:

When you have a problem, don't listen to what your computer tells you, but ask yourself what you were doing when the problem arose.

In my case, it means the following:
The problem popped up when I had upgraded my Visual Studio version (using the Visual Studio Installer), so the solution consisted of starting that Visual Studio Installer again, and check some more features to be installed (I've now checked so many of them that I can't figure out which one exactly solved my problem).

The error message, preceeded by the dialog box, were just information about the PC internals which only led to ununderstandable sidetracks.

4
  • 3
    Installing the missing frameworks from the Visual Studio Installer is what I needed to do. Thanks. Aug 5, 2018 at 18:03
  • ...which is exactly what your computer has told you to do. So DO listen to your computer (VS) when you have a problem! Jan 24, 2021 at 8:33
  • 1
    I had the same problem at build server. Installed the latest VS Build Tools 2019 (v16.11.5) and uninstalled the 2017. This was a mistake to make. No, VS Build Tools 2017 is not tied to .NET 4.5. You just have to re-launch the setup and Modify --> Individual Components: .NET Framework 4.5 targeting pack. The error was confusing. This solution helped!
    – J Pollack
    Oct 26, 2021 at 7:16
  • Lol, I will remember never to listen to my computer Oct 27, 2022 at 3:13
1

The boxes that I checked and seemed to work were ASP.NET framework, Office/Sharepoint development, Linux development with C++, and Visual studio extension development, all under workloads. Under the individual packages I checked every single .Net framework SDK and targeting pack.

That worked eventually.

1
  • 1
    As I mentioned in my answer, the problem was due to some "hanging" older application that was replaced during an upgrade, and restarting the Visual Studio solved the whole issue.
    – Dominique
    Aug 7, 2020 at 17:54
1

I was getting the same error on my net6 app. The build was happening on the solution and I had a reactApp included in my solution and it was doing a build on that.

I removed any Build & Deploy on that by:

Right click on my solution, -> Properties -> Configuration Properties ->

  • set Configuration to All Configurations
  • set Platform to All Platforms

then uncheck reactApp for Build and Deploy.

At the end on my CI/CD pipeline I saw:

The project "reactApp" is not selected for building in solution configuration "Debug|Any CPU".
1

I had the same issue in azure devops. my build was failing with same error message. What fixed mine was to install .net Framework 4.8 developer pack. You can download it here:

https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk

1

I downloaded and installed the developer pack at least 6 times. I opened the installer Modify/Individual Components/Checked all 4.8 boxes. Nothing seemed to work until I realised there was one little box on the right side not checked!

Visual Studio 2022 Installer Screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.