0
votes

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.

1
This GitHub issue discussion about .Net target versions/frameworks might help.Axel Kemper
When you call msbuild, did you use the developer command prompt of VS2017 to build the test project?Mr Qian
Could you provide more detailed info to describe your issue to help us troubleshoot the issue?Mr Qian
@PerryQian-MSFT No. I am running using a plugin/addin. Not sure which version is running - neither how to check which versionPALEN
@PALEN , After a deep research, I have found something about your issue. Please check my answerMr Qian

1 Answers

0
votes

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.