The "GetReferenceNearestTargetFrameworkTask" task was not found - visual-studio

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?

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.

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:
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.

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

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

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]

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

Related

Visual Studio 2017 RC installation failure "product ... cannot be found"

I am trying to install Visual Studio Professional 2017 RC on Windows 10 but the installer reports:
A product matching the following parameters cannot be found:
channelId: VisualStudio.15.Release
productId: Microsoft.VisualStudio.Product.Professional
Is this fixable?
I had the same issue and the following has helped me. A clean-up and removal of vs and installation folder was not enough in my case.
Here are the steps I've taken:
uninstalled Visual Studio (and other Visual Studio installations)
run C:\Program Files (x86)\Microsoft Visual Studio\Installer\InstallCleanup.exe -full"
removed all the "C:\Program Files (x86)\Microsoft Visual Studio" folders
removed "C:\Program Data\Microsoft\Visual Studio\ folder
restarted system
In the end I think removing of Program Data location did the final trick. I had to run a repair after the successful installation to make VS Extensions work.
I previously installed VS 15 Release and removed it. I had the same issue and fixed it by removing installer folder from here: C:\Program Files (x86)\Microsoft Visual Studio\ Installer
Please follow the cleanup steps and retry your VS install
See if you have this file on your machine: "%programfiles(x86)%\Microsoft Visual Studio\Installer\resources\app\layout\InstallCleanup.exe"
If so, please launch it from an admin command prompt with a -full param:
InstallCleanup.exe -full
If not, please manually delete the "%programfiles(x86)%\Microsoft Visual Studio\Installer” folder
Relaunch the newly downloaded vs_enterprise.exe (or vs_professional.exe or vs_community.exe…)
Allow the first step to install the installer
Once the installer comes up and you can see workload choices (.net desktop and the like), close it
Go launch the same InstallCleanup.exe to clean up old build of VS
Then relaunch vs_enterprise.exe and install VS.
The problem that I had was because I had a Visual Studio 2017 layout and I wanted to make a Visual Studio 2019 layout in the same directory.
If you are creating a new offline installation layout on top of an old offline installation layout, you need to delete every file inside the layout folder (And only the layout folder not sub-directories).
This way the new (channel) information will be replaced and installation goes without errors.

"C:\Microsoft.Cpp.Default.props" was not found

I have a project created in Visual Studio, 2013.
The project file has the following properties:
ToolsVersion="12.0",
PlatformToolset = v120.
I have Visual Studio 2013 and Microsoft Build Tools 2015 installed.
This project gets successfully built using MSBuild 12.0. Upon the attempt to build it with MSBuild 14.0 I get an error
MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
As I understand, the problem is that the variable VCTargetsPath doesn’t get evaluated. If I specify the variable VCTargetsPath before the build (with the value C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120), the problem is solved.
However, this approach is not very convenient in case the path is different. Is it possible to somehow solve the problem in a more optimal way?
The registry key and its value:
HKLM\Software\WOW6432Node\Microsoft\MSBuild\ToolsVersions\12.0\VCTargetsPath $([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\V120\'))
This will usually solve the problem:
Run on an elevated command prompt (admin):
npm install --global --production windows-build-tools.
npm is required and my recommended package manager.
Change ownership of the install dir (in my case C:\Program Files (x86)\MSBuild\14.0) to your user, instead of admin. (properties>Security>Advanced).
Sometimes step 2 is unnecessary. It is still recommended to avoid having to use admin console for some commands.
I recently reinstalled Visual studio 2017 and encountered this issue while trying to install "npm java".
The fix for me is:
set ms version to 2017: npm config set msvs_version 2017
set VCTargetsPath environment variable to C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets
run command console as system administrator
These steps solved my issue:
Run npm install --global --production windows-build-tools
Run npm install --save nan
Set VCTargetsPath environment variable to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
For those using VS 2019:
set VCTargetsPath="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160"
Edit (Sep 2020):
Sometimes it requires a trailing backslash (as bmiller mentioned below)
For those the above answer does not work, here is another possible solution to look at.
Even the installation of build tools or VS 2015 did not work for me. So I tried installing below directly via PowerShell (as admin)
https://chocolatey.org/packages/visualcpp-build-tools/14.0.25420.1
Command:
choco install visualcpp-build-tools --version 14.0.25420.1
Once this was installed, set an environment variable VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140
I solved this by:
Set VCTargetsPath environment variable to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
build using admin
I could not make it work with all the suggestions on this page
I downgraded nodejs to 10.15 and it worked fine
probably not the best answer but it works
When running MSBuild outside of Visual Studio 2019 (migrated from 2012), I had these kinds of problems.
I solved them running this MSBuild:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild"
(customize it based on your VS version and target architecture) instead of this one:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild
that I was using when I had Visual Studio 2012.
I solved the problem by loading the solution in VS 2019 instead of double-clicking the solution name in File Explorer.
My specific problem was using "yarn install" and during the build process, it was trying to build the node_modules node-sass component using MSBuild, and failing.
I would get the following error: "error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk."
This makes sense on a new developer machine with only Visual Studio 2022 installed. After investigating the node-sass module's build\binding.sln file, it appeared indicate that it requires Visual Studio 2015 VC++ Build Tools.
I then downloaded the "Visual C++ Build Tools for Visual Studio 2015 with Update 3" DVD image from Microsoft. After I installed it, it seemed to solve the problem, no PATH or registry changes required. When I ran "yarn install" again, building the module node-sass completed properly.
First I went to the path and confirmed that I didn't have that file. I was able to get that file by
opening the Visual Studio Installer,
clicking on "Modify" of the current installation
selecting "C++ Clang-cl v142 build tools (x64/x86)" under the Individual Components" tab.
Confirm the installation by clicking the "Modify" button
I tried npm install and VCTargetsPath, all not work. Finally solved after it after upgrading visual studio to the latest version.
Resolved by installing Visual Studio Express 2015 for Windows 10.
This happened for me when I used node version 14.15.3, install Node Version Manager, install lower Node version (8.x.x for example), switch to it and that should solve the issue.
After calling VS2019's vcvarsall.bat, it is necessary to use VS2019's MSBuild instead of the one in C:\Windows.
set VCVARSALL=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat
call "%VCVARSALL%" amd64
set MSBUILD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
rem set MSBUILD=%FrameworkDir%\%FrameworkVersion%\msbuild.exe
In my case, the reason was that the system environment variable VisualStudioVersion was pointing to the removed version of Visual Studio.
The same solution was building ok from inside the Visual Studio but failed when building with the command-line MSBuild.
The problem was solved by changing the environment variable manually.
I have VS 2019 and I met the same problem trying to install module 'keytar' on Windows 10. This is what I did in order to solve the problem:
Opened "Visual Studio Installer" and removed extra 2017/2019 build tools (for example "Visual Studio Build Tools 2017", restarted the PC
Got back into "Visual Studio Installer" / "Visual Studio Professional 2019" / "Modify" and added "Desktop development with C++" workload
Got into project folder with my problem, removed node_modules folder
Opened CMDO
As #TheRennen suggested performed the command:
set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\
(without quotation marks and with one backslash at the end)
run yarn command and now there were no errors.
I think now it a time to add VCTargetsPath into Windows env values.
node v14.19.0, npm 7.20.5, yarn 1.22.15
I have faced this issue while building my flutter application. The issue arises because of the program in my case flutter was unable to locate the file "Microsoft.Cpp.Default.props" which is required for building flutter apps in windows.
For solving the issue install MicroSoft Visual Studio(not Visual Studio code) from the below url.
https://visualstudio.microsoft.com/downloads/
Make sure to check the below option before starting installation.
After installation go to below directory.
C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Microsoft\VC
Note : I have installed community version of 2022 Visual Studio. The folder structure may be different based on your VS version
You can see few folders with version numbers
Open the folder and check which one have the "Microsoft.Cpp.Default.props" file . For my case it was the last folder v170. Open Environment variable and set "VCTargetsPath" variable with path to the folder in which "Microsoft.Cpp.Default.props" is present. Save path and restart the build process. This should work.
Make sure to use --global with the command in order to be able to use this package anywhere.
This solves the issue for me
While checking the .vcxproj file, I noticed the ToolsVersion was missing. I added it and it solves the issue.
Before :
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
After :
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

How to fix '"CheckAttributes" task could not be loaded'-error after installing Visual Studio 2013 Update 4

After installing Update 4, I now find myself unable to build (or even clean) any solution. I keep getting:
Error 1 The "CheckPathAttributes" task could not be loaded from the
assembly C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll.
Could not load file or assembly 'file:///C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll'
or one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements
Microsoft.Build.Framework.ITask. HandlePageNotFound
Does anyone know how to resolve this please?
Well, here's "my solution".
First the horrific "prompt of death" (plus the same "licensing issue" annoyance) in this post:
What I've attempted (and result) based on info from the interwebs:
Close VS 2013 and rename the folder:
C:\Users\[your user name]\AppData\Local\Microsoft\VisualStudio\12.0\ComponentModelCache
Result: No effect/errors persist (VS will re-create that folder on startup)
Rerun the Visual Studio Update 4 installer and Repair
Result: Successfully "fixed" whatever it was.
This will take about an hour which is slower than when I originally installed the update so that was a clue, or rather, more like "well, I hope that means it found what it did wrong or forgot/missed out on" (and not, "oh crap, now I'm really screwing things up even more")
A quick summary of my environment so that hopefully will guide you to your solution:
I did install Office Developer Tools Nov 2014 prior to the Update so in my case, that wasn't the issue (I did not remove/uninstall)
I have Resharper, and I did not disable it, so this too doesn't seem related (some have pointed this out)
I did update to Web Essentials 2013 for Update 4 after the initial Update (it will prompt you to after installing VS Update 4). I didn't do anything after the Repair (didn't remove/re-install/etc Web Essentials after the Repair).
I have VS 2012 as well, just mentioning this though that was never affected in any way (and was my fallback while this issue was stopping me from using VS2013)
Hth...
Found the solution via this
TransformXml task could not be loaded from Microsoft.Web.Publishing.Tasks.dll
In my case, I had Visual Studio 2012 installed on an E: drive already, so I found a copy of Microsoft.Web.Publishing.Tasks in
E:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web
So I copied that file, and Microsoft.Web.XmlTransform to here:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web
and now all is well :)
Uninstalling "Office Developer Tools for Visual Studio 2013 – November 2014 Update" helped me. Now all works as before.
If you have VS 2012 installed on your machine. Copy Microsoft.Web.Publishing.Tasks.dll and Microsoft.Web.Publishing.targets from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\web\ into C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web (the path for VS 2013). Restart visual studio.
I have only VS2013 (now with Update 4) and I solve this problem as follows: Close VS, copy "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.Dll" into the "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web" directory and start VS (folder v11.0 no contains Web subfolder). Now I can rebuild website projects without any error again.
My problem cleared thanks to the same TransformXml link and the suggestion to install Windows SDK for Windows 7 and .NET Framework 4
Copying "Microsoft.Web.Publishing.Tasks.dll" and "Microsoft.Web.XmlTransform.dll" from "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web" to "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web" also works

Installation of the Multi-Device-Hybrid CTP failed to add anything to VS

I installed the CTP of the multi-device-hybrid apps and the new app templates didn't show up in VS. The add-in also didn't show up in the Extensions & Updates list in VS. Trying to Uninstall it claimed to work instantly, but didn't uninstall anything.
This is an odd situation and should generally not occur. It seems the VSIX file got copied over but was not installed correctly.
Here's the work around (run using an administrative command prompt):
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common \IDE\VSIXInstaller.exe" /admin /uninstall:MultiDeviceHybridApps..db151788-9b27-49db-a5e2-d25a2653eb83
This removed the broken entries for the VSIX from the previous failed attempt to install. Following this, issue another command:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\VSIXInstaller.exe" "%localappdata\Microsoft\MultiDeviceHybridApps\Microsoft.VisualStudio.MultiDeviceHybridApps.vsix" /admin
At this point, the VSIX should be installed successfully and the templates will become available in Visual Studio.

Why is MSTest.exe not installed?

I have a dev machine and a build machine, both of which have Visual Studio 2012 Premium Update 3 installed (Version 11.0.60610.01). Both machines are 64 bit and are running Windows Server 2012 Version 6.2 (Build 9200)
The Dev machine has the following folder which contains MSTest.exe
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
On the build machine, that folder doesn't exist and searching for mstest.exe shows that it isn't on the build server anywhere.
Opening Control Panel > Programs and trying the Change operation doesn't provide any option to install mstest. All options shown in that Change window are identical on each machine.
The build server is also installed as a TFS agent
I've tried re-installing VS but no change.
Why isn't MStest.exe installed on the build machine and how can I get it installed?
I am using VS2017 and I was facing the same issue and I found it in here.
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE
Anybody using the VS2017 and facing the same issue can search the directory I have mentioned above to search MSTest.exe
Problem solved - the test components were on the F drive for some reason
This sounds like you did what I did.
If you install the update "2012.3" it will only install minimal components and not the full IDE. Try installing Visual Studio from the ISO (~2GB) and then apply the Update...
I found on a different directory:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe
EDIT: I came upon this page because I am trying to make the transition from Visual Studio to the Jetbrains Rider IDE and they assisted with some other questions on where to find dependencies for their command line Justmock runner here

Resources