0

I have msbuild version 14.0.25420.1 on my win10 command prompt computer, If I try to build a visual studio project file with this command:

 msbuild .\folder1\WxsGenerators.sln

I get an error

BUILD FAILED


  D:\Dev\Views\YY261307_main_sv\microsoft\MSBuild\Microsoft.Cpp\v4.0\Microsoft.Cpp.targets(40,5): error MSB4062: The "SetEnv" task could not be loaded from the assembly Microso 
ft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx. Could not load file or assembly 'Microsoft.Build.CppTasks.Common, Version=4.0.0.0,  
Culture=neutral, PublicKeyToken=xxx' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, th 
at the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [D:\path\TomtecWxs.vcxproj]

On my machine I have visual studio 2015 and visual studio 2019 installed. I need to figure out how to fix this error and build the .sln file, I've found a similar error posted here:

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

In the accepted answer, I tried to run the npm commands but was unable to do so, the other solution create .config file in the same dir as your exe (if you don't have it already) containing binding redirection of msbuild assemblies I am not sure how to do

Is there any way I can understand better / fix this "SetEnv" task could not be loaded from the assembly Microso ft.Build.CppTasks.Common error? Thanks

POVR2
  • 87
  • 10

1 Answers1

0

According to your description you find the solution but don’t know how to bind redirect msbuild assemblies in your porject. I can give you some suggestions about how to do that. You can create an app.config in your project folder to bind Redirects such as:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
    </startup>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Build.Utilities.Core" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
          <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Build.Framework" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
          <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
        </dependentAssembly>
     </assemblyBinding>
   </runtime>
</configuration>

You can look at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe.config and copy necessary blocks to your app.config in project folder.

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10