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 for VSIX project with VSSDK fails with MSB4062 for CompareBuildTaskVersion

See original GitHub issue

SDK Version: 3.1.301

If I run dotnet build on my repo, I get the following error:

d:.nuget\packages\microsoft.vssdk.buildtools\16.6.2058\tools\VSSDK\Microsoft.VsSDK.targets(90,5): error MSB4062: The “CompareBuildTaskVersion” task could not be loaded from the assembly d:.nuget\packages\microsoft.vssdk.buildtools\16.6.2058\tools\VSSDK\Microsoft.VisualStudio.Sdk.BuildTasks.16.0.dll. Could not load file or assembly ‘Microsoft.VisualStudio.Sdk.BuildTasks.16.0, Version=16.0.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.Build.Framework.ITask. [D:\repos\Path\To\My.csproj]

If I just run msbuild (16.6), it builds successfully.

I can see in the binlogs that the same targets being executed (VerifyTargetVersion in Microsoft.VsSDK.targets executes CompareCommonBuildTaskVersion - which succeeds in both cases - and then CompareBuildTaskVersion - which succeeds with msbuild but fails with dotnet build).

I’m not sure whether this is a VSSDK issue or a dotnet sdk issue, but since it worked in vanilla msbuild, I figured I’d start here.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

16reactions
drewnoakescommented, May 13, 2021

I hit this, building a VSIX project in an internal VS2022 build (17.0.0 Preview 1.0 [31312.303.main]):

MSB4062: The “CompareBuildTaskVersion” task could not be loaded from the assembly D:\myproject\packages\Microsoft.VSSDK.BuildTools.15.8.3253\tools\VSSDK\Microsoft.VisualStudio.Sdk.BuildTasks.15.0.dll. Could not load file or assembly ‘file:///D:\myproject\packages\Microsoft.VSSDK.BuildTools.15.8.3253\tools\VSSDK\Microsoft.VisualStudio.Sdk.BuildTasks.15.0.dll’ or one of its dependencies. An attempt was made to load a program with an incorrect format. 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.Build.Framework.ITask.

Upgrading the Microsoft.VSSDK.BuildTools package from 15.8.3253 to 16.9.1050 resolved the issue.

1reaction
GrahamTheCodercommented, Jul 2, 2021

@kfertitta I have the same issue and also believed I needed the build tools that matched the oldest version supported. But I just tried building with the 17.0 prerelease build tools and found the result ran fine on 16.9. Perhaps that was just good luck, or perhaps only the SDK (and interop types) need to be the oldest version, but the build tools can be later? Example from Mads Kristensen of a 2017 extension with 2022 build tools: https://github.com/madskristensen/ExtensionPackTools/commit/e7ec8d5796c93da2b347e78a2eef3fdaa3356f3d#diff-64358be7ce06ce02708ac447688269a3d49c797d5610e9b60248a697a3dbf899R115

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot build VSIX package project using "dotnet ...
VsSDK.targets(89,5): error MSB4062: The “CompareBuildTaskVersion” task could not be loaded from the assembly […]\packages\Microsoft.VSSDK.
Read more >
Porting my Visual Studio Parameters.xml Generator tool to ...
When I tried build the existing solution, without any changes, in Visual Studio 2022 I got the error. MSB4062: The "CompareBuildTaskVersion" ...
Read more >
VSSDK: can't build solution with mixed style csproj-projects ...
VisualStudio.Sdk.BuildTasks.dll from VSSDK. So a VSIX project cannot be built with dotnet CLI. Then I try to build via msbuild.
Read more >
Deploying Web Application in IIS Using Visual Studio 2019
error MSB4062 : The "CompareBuildTaskVersion" task could not be loaded from the assembly D:\BuildSystem15\OutsideView\packages\Microsoft.VSSDK.
Read more >
Visual Studio Extension project when built in VS2022 ...
Open same project in VS2022 and change the reference of dependent dlls to use latest compatible version and build the project. We get...
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