Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResolveComReference task could not be loaded

Win7, VS2017, ASP Net core app, target framework is 4.6.

When I try to build my project with CLI (it is needed before dotnet commands calling) the error occurs:

C:...\Microsoft.Common.CurrentVersion.targets(2547,5): error MSB4062: The "Microsoft.Build.T asks.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 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. [C:\project.csproj]

I have been looking for questions related with my issue and have done the following things:

  • restart VS
  • clean and build the project with VS tools (it was successfully)
  • load Microsoft.Build package
  • remove content of packages folder and reload it

But nothing helps me.

What it can be?

like image 285
Ilya Loskutov Avatar asked May 22 '17 18:05

Ilya Loskutov


1 Answers

COM references are not supported by the .net core version of MSBuild which is what the .NET CLI uses. For those references to work, you have to build your project using msbuild directly. Using the Developer Command Prompt for Visual Studio 2017 you should be able to perform the build using commands like:

msbuild /t:Restore
msbuild /t:Build /p:Configuration=Release
msbuild /t:Publish /p:Configuration=Release

(you can also add /m to enable parallel builds).

This reference is also unsupported when running CLI tools that use these project files since they also rely on the .NET Core version of MSBuild.

However, there is a workaround that will enable CLI tools to be able to use the project, but it will not allow them to fully build using the .NET Cli. Add the following Condition attribute to your ComReference items to "hide" the COM reference when building with the .NET Core version of MSBuild:

<COMReference Include="FooBar" Condition="'$(MSBuildRuntimeType)' != 'Core'">
  <Guid>{some-guid}</Guid>
  <!-- a lot more metadata elements -->
</COMReference>
like image 142
Martin Ullrich Avatar answered Oct 22 '22 13:10

Martin Ullrich