question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dotnet build error MSB4062: The "Microsoft.Build.Tasks.ResolveComReference"

See original GitHub issue

Steps to reproduce

  • create console app
  • add com reference for example: FirewallAPI.dll
    <COMReference Include="NetFwTypeLib.dll">
      <Guid>58fbcf7c-e7a9-467c-80b3-fc65e8fcca08</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>0</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>tlbimp</WrapperTool>
      <Isolated>false</Isolated>
    </COMReference>
  • dotnet build
  • dotnet publish -c Release -r win-x64

Expected behavior

Console application will produce .exe file

Actual behavior

C:\GIT\ImgPoolCS>dotnet.exe publish -c Release -r win-x64 -f netcoreapp2.0
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for C:\GIT\ImgPoolCS\LiCS.csproj...
  Installing Microsoft.NETCore.DotNetAppHost 2.0.7.
  Installing Microsoft.NETCore.DotNetHostResolver 2.0.7.
  Installing Microsoft.NETCore.DotNetHostPolicy 2.0.7.
  Installing Microsoft.NETCore.App 2.0.7.
  Installing Microsoft.NETCore.Platforms 2.0.2.
  Installing runtime.win-x64.Microsoft.NETCore.DotNetAppHost 2.0.7.
  Installing runtime.win-x64.Microsoft.NETCore.DotNetHostResolver 2.0.7.
  Installing runtime.win-x64.Microsoft.NETCore.DotNetHostPolicy 2.0.7.
  Installing runtime.win-x64.Microsoft.NETCore.App 2.0.7.
  Generating MSBuild file C:\GIT\ImgPoolCS\obj\LiCS.csproj.nuget.g.props.
  Generating MSBuild file C:\GIT\ImgPoolCS\obj\LiCS.csproj.nuget.g.targets.
  Restore completed in 57,42 sec for C:\GIT\ImgPoolCS\LiCS.csproj.
C:\Program Files\dotnet\sdk\2.1.301\Microsoft.Common.CurrentVersion.targets(2725,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveComReference" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0
, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Bui
ld.Framework.ITask. [C:\GIT\ImgPoolCS\LiCS.csproj]

Same error is produced by dotnet build If I run this project in Visual Studio 2017 and build a release and debug, everything is fine. No error is produced. But this unfortunately does not produce .exe file.

Environment data

.NET Core SDK (reflecting any global.json):
 Version:   2.1.301
 Commit:    59524873d6

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.301\

Host (useful for support):
  Version: 2.1.1
  Commit:  6985b9f684

.NET Core SDKs installed:
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.105 [C:\Program Files\dotnet\sdk]
  2.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jhudsoncedaroncommented, Jan 17, 2020

So I’m going to leave this here because searching for the error yields this page.

COM References don’t work when building with the .NET Core 3.1 LTS Toolchain. Use tlbimp to make a PIA dll and link against that instead.

We’re opting to use a specific version of the .NET Core toolchain for building .NET Framework projects to keep installed updates from breaking the build tools anymore and we want to be able to build the product a decade from now.

0reactions
nicovv44commented, Jul 22, 2021

A remark has been added (4 Jun 2020) about error MSB4803 on the documentation page of ResolveComReference task

If you try to run a project that uses the ResolveCOMReference task from the dotnet CLI commands, you may get the error:

MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild.

This task is not supported on the .NET Core version of MSBuild, which is what’s used when you run the dotnet build command from the command line. Try building the project by invoking MSBuild.exe from the Visual Studio Developer Command Prompt, since this uses the .NET Framework version of MSBuild.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET Core error on build: error MSB4062 Microsoft.Build. ...
.NET Core error on build: error MSB4062 Microsoft.Build.Tasks.ResolveComReference ... I'm working on a .net core web app (targeting net461). The ...
Read more >
ResolveComReference Class (Microsoft.Build.Tasks)
On a 64-bit machine, Framework64/<version>/msbuild cannot resolve COM objects registered as 32-bit components. For example, if you register a COM object ...
Read more >
ResolveComReference Task - MSBuild
MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild.
Read more >
MSB4062 - MSBuild
This error is emitted when a task assembly cannot be loaded prior to executing a task.
Read more >
net – ResolveComReference task could not be loaded
CurrentVersion.targets(2547,5): error MSB4062: The "Microsoft.Build.T asks.ResolveComReference" task could not be loaded from the assembly Microsoft.Build.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found