76

I have a problem with autocompletion in VS 2017 Community.

Previously I had VS 2017 Enterprise from school, but the key expired so I moved to Community.

Before, everything works great, but now it doesn't work at all.

I found a solution on Stack Overflow here but it doesn't work, so found another solution at GitHub here.

And I got this:

Build FAILED.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1601,5): error MSB4036: The "GetReferenceNearestTargetFrameworkTask" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin" directory. 0 Warning(s) 1 Error(s)

Time Elapsed 00:00:00.11

Do you know what to do next?

Null
  • 1,950
  • 9
  • 30
  • 33
LadIQe
  • 895
  • 1
  • 6
  • 8
  • On the top of your question you said that autocomplete is not working. On the bottom, you that you got error. Which one is actually happening at this moment? – Programmer Dec 13 '17 at 16:13
  • error is from: xxxxx_Compile_8f49089d.designtime.log which is output from VS 2017, autocomplete is not working in VS due to error from log – LadIQe Dec 13 '17 at 16:20
  • If you experience this problem, please vote for the bug report at https://developercommunity.visualstudio.com/content/problem/137779/the-getreferencenearesttargetframeworktask-task-wa.html – Colonel Panic Mar 07 '18 at 16:21

6 Answers6

76

I had the same error message but for a different problem.

So, I'm using MSBuild to automate build/deploy process for Azure Functions. Everything was working fine until I updated both Visual Studio 2017 and Visual Studio Build Tools 2017 at which point I started getting this error. To be precise I got this error only when using MSBuild, building project manually from VS was working fine.

In my case I already had everything set as per @Programmer's answer. But as I was using MSBuild it turned out that I also had to install NuGet targets and build tasks which are part of Visual Studio Build Tools.

Screenshot of Visual Studio Installer

Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
  • 4
    This works for me also and I had done the same, updating Visual Studio Build Tools 2017. This was for a build server and Visual Studio 2017 itself is not installed. Just simply re-run the build tools installer and add the 'NuGet targets and build tasks' component. – tjmoore Jan 11 '18 at 19:25
  • This is the actual solution to the error message. In most cases you'll already have the nuget package manager installed from an earlier version of Visual Studio or a standalone version (from https://www.nuget.org/downloads, ~5 MB). Also note that for some reason, picking "NuGet Package Manager" as indicated by the accepted answer instead of "NuGet targets and build tasks" will try to install over 900 MB on your disk; I can only guess that it tries to preinstall some common packages - can someone confirm? The "targets" option is only ~13 MB. – MrCC Jul 26 '18 at 10:52
  • I am using Jenkins, with slave windows machine, where I have MSbuild tools installed and no VS. With the GUI installer of the MSBuild tools, I have installed the above mentioned and all worked out properly. – ChristoD Nov 14 '18 at 09:47
  • I installed the MSBuild Tools as instructed above, however I don't see the nuget.exe in the folder I've designated the Location as: C:\BuildTools. I did a search within that folder for "nuget.exe" and am not finding it. – Rob Koch Mar 18 '19 at 19:12
71

Follow these to fix that error. This applies to VS 2017:

Fix 1:

1.Install Nuget PackageManager from here.

2.Restart Visual Studio.


If the problem is still there, continue below

Fix 2:

1.Download and start/run the Visual Studio Installer again.

2.While the Visual Studio Installer is still running, go to the "Individual Components" tab

3.Tick the "NuGet package manager" check-box that is under "Code tools" option.

4.Click Install to install it.

Screenshot of where this is located:

enter image description here

That should fix the error you see in this question. Restart Visual Studio and test the auto-completion function. If it's not working, see the answers from this question as that is a whole different issue.

Dealdiane
  • 3,984
  • 1
  • 24
  • 35
Programmer
  • 121,791
  • 22
  • 236
  • 328
27

I was seeing this issue with msbuild 15.6.82 on a build environment that does not have VisualStudio 2017, only VS Build Tools.

Here's a PowerShell script that resolves this issue, it pretty much does the equivalent of previous answers in the VS Installer, but silently and waiting for completion.

Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList 'modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" --quiet --add Microsoft.VisualStudio.Component.NuGet.BuildTools --add Microsoft.Net.Component.4.5.TargetingPack --norestart --force' -Wait -PassThru

propagated
  • 4,212
  • 1
  • 24
  • 26
  • 2
    It's also possible to download [vs_BuildTools2017.exe](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017) which acts as an online installer for the various options - see, e.g. [this question](https://stackoverflow.com/q/42696948/1364007) about how to use it. – Wai Ha Lee Jul 30 '18 at 16:56
18

I'm working with a headless build server on server core, resolved by installing chocolatey package choco install visualstudio2017-workload-webbuildtools from here:

https://chocolatey.org/packages?q=msbuild

David Cobb
  • 680
  • 6
  • 11
1

I'm reporting an answer from a Microsoft techician

This usually indicates one of two things:

  • A failed VS installation. If that's the case, I would recommend running a repair on your VS install.
  • You have msbuild assemblies in the GAC. If that's the case, please ungac them.

Livar Cunha [MSFT]

Revious
  • 7,816
  • 31
  • 98
  • 147
0

I got the same problem in Visual Studio 2019, I solved it by simply install unity package