locked
Using XSD task I'm getting MSB0001: Internal MSBuild Error: xsd.exe unexpectedly not a rooted path RRS feed

  • Question

  • I'm trying to use the XSD task to convert a schema file to a C# file.

    In my csproj file I have the following:

     <UsingTask TaskName="XSD" AssemblyName="Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     <Target Name="BeforeBuild">
      <XSD Sources="MySchema.xsd" GenerateFromSchema="classes" Language="CS">
      </XSD>
     </Target>
    
    

    When I try to build the project I get the following error reported:

    error MSB4018: The "XSD" task failed unexpectedly.
    error MSB4018: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: xsd.exe unexpectedly not a rooted path
    error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Object[] args)
    error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInternalRooted(String value)
    error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.TrackerExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
    error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
    error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute()
    error MSB4018: at Microsoft.Build.CPPTasks.TrackedVCToolTask.Execute()
    error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

     

     

     

    Any suggestion as to what I've got wrong (I can't find a working example of using XSD task)?

    Dave

    Thursday, August 5, 2010 11:11 AM

Answers

  • Hello David,

    Yes, I loads this into VS 2010, it did occur this error. This error message indicates it can't find xsd.exe. So I try to add the path of xsd.exe and Microsoft.Build.CppTasks.Common.dll to Environment Variable, restart my computer. It works fine again.

    The path of xsd.exe and Microsoft.Build.CppTasks.Common.dll are:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\;
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0

    Or you also can add following command line in your Pre-build event to achieve this:

    xsd.exe /classes /language:CS MySchema.xsd

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 6, 2010 10:14 AM

All replies

  • Hi Dave,

    I write a project file with <XSD> task, and it works fine in my side. See Code in my project file:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
     <UsingTask TaskName="XSD" AssemblyName="Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <Target Name="test">
       <XSD Sources="MySchema.xsd" GenerateFromSchema="classes" Language="CS">    
       </XSD>    
     </Target>
    </Project>
    
    

    And I run it using MSBuild command in Visual Studio Command Prompt (2010). Build succeeded.

    So I guess the problem is you don't use MSBuild 4.0 to build your project file. Please refer to my steps to see if these error messages still exists.

    Please let me know the result.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 6, 2010 3:15 AM
  • Hi Nancy,

    I'm not sure what you mean when you say "So I guess the problem is you don't use MSBuild 4.0 to build your project file. ".

    so... I've opened a VS2010 command prompt and run:

        MSBuild YourExample.csproj

    ... and that works.

    Is that what you were referring to?

    However, if I load that csproj file into a VS2010 solution and attempt to build it, I get the same error as I do with my project.

    So, what happens if you load your example into VS2010?

    Dave

    Friday, August 6, 2010 8:47 AM
  • Hello David,

    Yes, I loads this into VS 2010, it did occur this error. This error message indicates it can't find xsd.exe. So I try to add the path of xsd.exe and Microsoft.Build.CppTasks.Common.dll to Environment Variable, restart my computer. It works fine again.

    The path of xsd.exe and Microsoft.Build.CppTasks.Common.dll are:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\;
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0

    Or you also can add following command line in your Pre-build event to achieve this:

    xsd.exe /classes /language:CS MySchema.xsd

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, August 6, 2010 10:14 AM
  • Fantastic.

    I've spent the best part of a day on this being mislead by that message "Internal MSBuild Error: xsd.exe unexpectedly not a rooted path" which comes down to the fact that the IDE didn't have a path to the xsd.exe command - why couldn't it have said that?

    Thanks for pointing that out anyhow.

    Out of interest, how did you come to the conclusion that was the problem?

    As a suggestion, since there's this build task, and the IDE seems to manage to make use of XSD facilities in other circumstances, shouldn't the IDE automatically have XSD accessible (without the user having to botch their path environment variable)?

    Dave

    Friday, August 6, 2010 10:35 AM
  • BTW, I didn't find any need to add the path for the build task - that works out of the box. Only the path for xsd.exe was needed.
    Friday, August 6, 2010 10:44 AM
  • I've submitted a report on Connect.

    https://connect.microsoft.com/VisualStudio/feedback/details/583931/xsd-exe-should-be-accessible-from-ide-builds

    Anyone remotely interested - please add a vote/whatever for it.

    Ta
    Dave

    Friday, August 6, 2010 1:12 PM
  • Hello Dave,

    Thanks for your sharing. I'm not sure it's by design or an issue with Visual Studio. So it's a great idea to submit a feedback in our connect portal, and our product team will evaluate carefully and they will let you know their comments further through that portal. Thanks.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, August 9, 2010 2:12 AM
  • This is a non-maintainable solution. It works, but doing this for n-tools in a project it is utterly deficient. Now, every dev has to add this as a pre-step before they can use VS for a project that uses XSD.

    Better to copy xsd.exe into a private tools directory and add that to your enlistment so the binary is in a dependable location and of a known version. This is (or was) standard practice inside MSFT.

    Wednesday, March 21, 2012 4:01 PM
  •  adding the path of xsd.exe and Microsoft.Build.CppTasks.Common.dll to Environment Variable, restarting computer worked for me.
    Monday, January 15, 2018 8:26 AM