ResolveComReference task could not be loaded

不问归期 提交于 2021-02-18 06:02:04

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/44119631/resolvecomreference-task-could-not-be-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!