Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error MSB4062: The "SetEnv" task could not be loaded from the assembly

So I am trying to install a Node package called better-sqlite-pool, however I am stuck with an error which I can't seem to resolve. Whenever I run npm i better-sqlite-pool, I get the following error:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Current.targets(64,5): error MSB4062: The "SetEnv"
 task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Build.CppT
asks.Common.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, Pu
blicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the
<UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contain
s a public class that implements Microsoft.Build.Framework.ITask. [D:\Files\ScrimsBot\node_modules\integer\build\intege
r.vcxproj]

I have done extensive research on this, and have tried pretty much all of the suggested fixes to no success.

The first error I received I managed to fix by adding an environment variable of VCTargetsPath and setting it to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140. The error I received before doing this was the following:

The imported project "D:\Microsoft.
Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exist
s on disk.

Another thing I tried was installing the build tools using the npm install -g --production windows-build-tools command however that made no difference.

It is probably worth noting that I have Visual Studio 2017 Enterprise installed with the VC++ 2015.3 v14.00 (v140) toolset for desktop component installed.

like image 964
Luke Avatar asked Sep 29 '18 14:09

Luke


People also ask

Where is the assembly manager located in Windows?

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe --- A detailed error log follows.

Why can't I find MSBuild cpptasks in Visual Studio 2017?

Microsoft.Build.CPPTasks.Common cannot find Microsoft.Build.Tasks.Core It seems you are using the old MSBuild.exe from .NET framework. You should use the MSBuild.exe from following location after you upgraded your project from VS2012 to VS2017:

What version of MSBuild fails on Ajax Extensions 2?

9 MSBUILD 4.0 Fails on AJAX Extensions 2 Visual Studio 2017 msbuild package sharepoint 95 Could not load file or assembly 'Microsoft.Build.Framework'(VS 2017)

When does Visual Studio stop building when using MSBuild 12?

Visual Studio Android solution stops building upon hitting C# version conflict when using MSBuild 12 Visual studio conflicts between Reference and Platform 0 The type 'HttpResponseMessage' is defined in an assembly that is not referenced


2 Answers

I have a rather similar issue, and got stock at the same point. I found two possible solutions over here:

  • install Visual Studio 2015 as well
  • create .config file in the same dir as your exe (if you don't have it already) containing binding redirection of msbuild assemblies

The first option works for me:

  • use an administrator prompt from the current user, don't elevate from a limited user, the paths will be a mess if you do that
  • npm install --global --production --vs2015 windows-build-tools
  • npm install --global --production windows-build-tools (this one gets stuck during the installation, ctrl-c to end it)
  • npm install --global --production windows-build-tools (yes, the same command again to finish the configuration)
  • npm config set msvs_version 2015 --global

Since I'm not a real programmer I wouldn't know where to begin for the latter option.

like image 190
Milmoor Avatar answered Oct 17 '22 01:10

Milmoor


You don't need full 2015 vs you can install msbuild 2015 component https://www.microsoft.com/en-us/download/details.aspx?id=48159 you might need to be sure to user the added msbuild in your path

You might use a similar command if new msbuild isn't found (even after reboot)

set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%

in cmd.exe

like image 39
Et7f3XIV Avatar answered Oct 17 '22 03:10

Et7f3XIV