0

When I do msbuild for the .csproj project, it successfully builds.

However, when trying to (build and) run a test in VS2017, I get the following error:

The "Xsd" task could not be loaded from the assembly Microsoft.Build.CppTasks.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Could not load file or assembly 'Microsoft.Build.CppTasks.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 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.

I tried solutions in this post but unfortunately did not work. Please be specific/practical in your suggestions.

PALEN
  • 2,784
  • 2
  • 23
  • 24
  • [This](https://github.com/Azure/azure-functions-vs-build-sdk/issues/160) GitHub issue discussion about `.Net` target versions/frameworks might help. – Axel Kemper Aug 17 '20 at 08:03
  • When you call msbuild, did you use the developer command prompt of VS2017 to build the test project? – Mr Qian Aug 18 '20 at 02:09
  • Could you provide more detailed info to describe your issue to help us troubleshoot the issue? – Mr Qian Aug 18 '20 at 02:55
  • @PerryQian-MSFT No. I am running using a plugin/addin. Not sure which version is running - neither how to check which version – PALEN Aug 18 '20 at 02:59
  • @PALEN , After a deep research, I have found something about your issue. Please check my answer – Mr Qian Aug 18 '20 at 08:37
  • @PALEN, I have updated my answer and you can check it. – Mr Qian Aug 19 '20 at 02:39
  • @PALEN, any update about this issue? Since you use VS2017, I suggest you could try updated answer to put that dll into GAC to resolve this issue. If my answer helps you handle this issue, please do not forget to mark it. If not, please feel free to let us know. – Mr Qian Aug 21 '20 at 02:48

1 Answers1

0

Cannot build and run test in C# : The “Xsd” task could not be loaded from the assembly Microsoft.Build.CppTasks.Common, Version=12.0.0.0

Just as this document said, Xsd task has been deprecated from MSBuild since VS2017.

enter image description here

And it seems that your own project has something that needs to be compiled by the MSBuild XSD Task, so this error appears.

And your plugin should use MSBuild of VS2015 or earlier MSBuild to build this test project. So the error did not happen there.

Suggestion

1) So you should VS2015 or earlier VS to build your project.

2) Or you could manually add CppCodeProvider.dll to the GAC under VS2017 and then you could build it in VS2017.

Solution

Run CMD as Administrator and then run:

cd C:\Program Files (x86)\Microsoft Visual Studio\2017\xxx\Common7\IDE\PublicAssemblies

gacutil /i Microsoft.VisualC.VSCodeProvider.dll

================================================

Update 1

It is quite strange why MSBuild of VS2017 will call a task dll from VS2013.

Microsoft.Build.CppTasks.Common, Version=12.0.0.0 is from VS2013.

So please try the following steps:

1) check whether you have defined a system environment variable called VCTargetsPath and check if its value is related VS2013. Anyway, you should delete that variable and then restart VS to test again.

2) also try to register these dlls into GAC:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Build.CPPTasks.Common.dll

or C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Build.CPPTasks.Common.dll

3) disable any third party extensions under Extensions-->Manage Extensions

4) try to repair VS or update VS to check if VS has broken.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Did the CMD run as Admin (gcutil). Got the following: Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0 Copyright (c) Microsoft Corporation. All rights reserved. Assembly successfully added to the cache. Unfortunately, still getting the same error :( – PALEN Aug 21 '20 at 05:03
  • Actually, it is quite strange why your MSBuild of VS2017 is call a file from VS2013.` Microsoft.Build.CppTasks.Common, Version=12.0.0.0` is from `VS2013`. And I am quite confused that why MSBuild will call a dll of VS2013. Did you open the project in VS2017 and build it? Also, I have updated my answer and you can check it. – Mr Qian Aug 21 '20 at 10:01
  • Update. 1) I don't have that var. 2) Tried, didn't work (was able to register the first dll, don't have the second). 4) Tried, didn't work. Also, "It is quite strange why MSBuild of VS2017 will call a task dll from VS2013": I am running it through an addin, not sure how it operates which dll's/versions it calls. – PALEN Aug 21 '20 at 21:26
  • Can you please disable that `addin` and use msbuild of VS2017 to build the project. The issue is in your addin. I'm pretty sure. And it may have a separate build tool of its own that we're not even sure about. And it may have a bit difference from VS2017 and may be defective. So please disable it and test in your VS2017.Open the project in VS2017 and then click `Build` to check where the issue. – Mr Qian Aug 24 '20 at 06:34