156

When trying to compile a solution, I get the following build error:

Error MSB3644 The reference assemblies for framework ".NETFramework,Version=v4.6.2" 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. C:\RPR\Dev\Libraries\Common\Common.csproj C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 1111

I've tried installing the .NET Framework 4.6.2 SDK, as well as the 4.6 Targeting Pack, however both error that I already have it installed. I also tried installing Visual Studio 2017 but it still gives the same error.

Any ideas?

Justin
  • 17,670
  • 38
  • 132
  • 201

13 Answers13

127

Windows -> Search -> Visual Studio Installer -> Modify -> Individual Components and check the right version

Cata Hotea
  • 1,811
  • 1
  • 9
  • 19
  • 14
    This is a clean solution as Visual Studio will list all the versions for you and shows what you currently have installed and will manage the download/install. – olive_tree Aug 23 '18 at 17:35
  • 1
    Tried all the solutions above and none worked. This one did the job. Thanks – Charlie S Sep 03 '18 at 10:55
  • Mine is asking for v4.6.1 (reference assemblies) and it shows v4.6.1 (development tools) installed via the installer... still trying to figure out what's going on. CANCEL THAT: My issue was that none of the .NET framework was installed at all by default. Thank you. – Xonatron Jan 02 '19 at 01:44
  • 1
    This should seriously be the top answer! – Tomáš Hübelbauer Jul 08 '19 at 14:42
  • 1
    This one is the best answer! – Himechi90 Oct 20 '19 at 22:12
  • If the error asked you to install the developer version, in the individual list mark SDK version, the Targeting Pack did not solve the issue. – Bashir Momen Jun 09 '20 at 13:16
  • I had to do it through the installer and not the self installer .. – Ken Jul 30 '20 at 21:49
  • I needed to understand how to modify the individual components of Visual Studio. This is the answer I was looking for. upvoted - Thanks! – swifty Aug 19 '20 at 03:37
  • In visual studio 2019, Tools -> get tools and features -> .NET Desktop environment – Ebrahim Karam Feb 24 '21 at 00:14
109

It turns out that I had installed the .NET Framework v4.6.2, not the Developer Pack for 4.6.2. Doh!

https://www.microsoft.com/en-us/download/details.aspx?id=53321

Justin
  • 17,670
  • 38
  • 132
  • 201
34

Starting May, 2019 you can build your project on net20 up to net48 (including ne461) any machine with at least MSBuild or the .NET Core SDK installed without the need of Developer Pack installed.

If .NET Core SDK installed in you machine, Add the nuget package Microsoft.NETFramework.ReferenceAssemblies to your project

    <ItemGroup>
        <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>     
    </ItemGroup>

The package include all ReferenceAssemblies starting net20 up to net48

These packages enable building .NET Framework projects on any machine with at least MSBuild or the .NET Core SDK installed plus other scenarios.

For more details: https://github.com/Microsoft/dotnet/tree/master/releases/reference-assemblies

Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
M.Hassan
  • 10,282
  • 5
  • 65
  • 84
19

Installing the 4.6.2 Developer Pack did not work for me.

I had to install .NET Framework 4.6 Targeting Pack

MonkeyDreamzzz
  • 3,978
  • 1
  • 39
  • 36
13

I was getting the exact same error when building except it was for ".NETFramework,Version=v4.7.1".

I downloaded the Developer pack for 4.7.1 from here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=56119

The pack installed these programs on the target machine (my build server).

  • Microsoft .NET Framework 4.7.1 SDK
  • Microsoft .NET Framework 4.7.1 Targeting Pack
  • Microsoft .NET Framework 4.7.1 Targeting Pack (ENU)

When I tried building again, I didn't get the error anymore and the build succeeded.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
7

For 4.7.2 issue I have to go here: https://dotnet.microsoft.com/download/dotnet-framework/net472

Install the Download .NET Framework 4.7.2 Developer Pack as displayed in the image to fix the issue.

enter image description here

Raghav
  • 8,772
  • 6
  • 82
  • 106
2

I was using ubuntu and faced the same problem. Even after I've downloaded latest vscode and mono for ubuntu it was not working. Then I found this.
Basically if you've installed mono then go to settings and set

"omnisharp.useGlobalMono": "always".

hope it fix your issue.

1

Check the installed .net framework on your development machine, it must be the same as project file targeting. You need to install the .net framework which the project file targeting after that try again the errors and warnings will disappear.

PSTech
  • 11
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 18 '21 at 19:04
0

you can find this omnisharp setting inside Visual Studio C# extensions settings and go to the botton.

enter image description here

Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
Ro D
  • 41
  • 2
0

Download required SDK package with link , .net framework 4.6.2 developer pack download-link and install. Restart the server, now build will be successful.

You can check dotnet version with dotnet --info

Aditya Y
  • 651
  • 6
  • 12
0

In my case, (I'm embarrassed to admit) I had a website loaded as a project and forgot to set it to No Build.

Jeremy Hodge
  • 612
  • 3
  • 14
0

Install VS2019 and select Framework 4.x.x targeting packs. That helped me to sort this error.

Previous VS installers are hidden in here

https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes

CharithJ
  • 46,289
  • 20
  • 116
  • 131
0

If you've recently installed Unity on Ubuntu 22 and intend to use VS Code for development, chances are you're reading this after you've tried a number of ways and none of them worked...


I was in the same situation and the following worked for me:

  1. Uninstall VS Code C# extension (may need to remove all extensions associated with C#)
  2. Reinstall mono and mono-msbuild
    1. sudo apt install gnupg ca-certificates
    2. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
    3. echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
    4. sudo apt update
    5. sudo apt install mono-roslyn mono-complete mono-dbg msbuild
  3. Reinstall VS Code C# extension
  4. Set omnisharp.useModernNet to false in VS Code File / Preferences / Settings
  5. Restart VS Code

Update

And now, after another Ubuntu update, this solution stopped working ...

However, I found a simpler and cleaner solution!

In my case, all the previous steps were completed and I did not check, maybe some of them are no longer needed.

You need to install the Unity and C# Dev Kit extensions in VS Code.

Also you need to keep this requirements:

  • Unity 2021 or greater.
  • Activated C# Dev Kit extension in Visual Studio Code.
  • .NET 7 SDK or greater, the C# Dev Kit will install it if required.
  • Visual Studio Editor Unity package 2.0.20 or greater.

Sources:

wowandy
  • 1,124
  • 2
  • 10
  • 23