I am using MSBuild Community Tasks to run Xsd.exe as part of my build in Visual Studio as thus:
<Import Project="$(SolutionDir)Common.targets" /> <PropertyGroup> <MSBuildCommunityTasksPath>$(SolutionDir)TeamBuildTypes</MSBuildCommunityTasksPath> </PropertyGroup> <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" /> <UsingTask TaskName="XSD" AssemblyFile="$(VCTargetsPath)$(CPPTasks)" /> <Target Name="BeforeBuild"> <!--Exec Command="'$(DevEnvDir)..\Tools\vsvars32.bat'" /--> <XSD Sources="MySchema.xsd" GenerateFromSchema="classes" Language="CS" /> </Target>
Common.targets is as per here.
However, I get the following error during build:
The "XSD" task failed unexpectedly.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: xsd.exe unexpectedly not a rooted path
A solution has been given on MSDN forum here, which is to add a path to xsd.exe to the path environment variable. But, as indicated by Pico Ohms' answer, this is not maintainable as it is version-dependent and requires every dev to perform an extra step in order to build, just because of Xsd.exe.
I found another solution here which is to call vsvars32.bat beforehand. This is the commented-out line in the code above. This didn't work, so I found a solution here that I hoped would make it work, which was to call DEVENV with the
Then I found another solution here which is to add
<xs:include schemaLocation="MSBuild\MSBuild.Community.Tasks.xsd"/> to Microsoft.Build.xsd. Didn't work either.
So, now I'm out of ideas. How do I get the MSBuild Community Tasks XSD task working without requiring devs to update their path variable, either by using the
/useenv solution, or some other solution? I'm aware I can put xsd.exe in the Visual Studio solution, but this seems like a cheap workaround to me.