The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,343 other followers

Finding the path of xsd.exe from your Visual Studio Build Events

Posted by jpluimers on 2015/05/05

I wrote about the xsd.exe tool before to generate XSD from XML:

But it is much more than that, as it is a great way of generating .NET (not only C# and VB.NET code) from XSD files:

Long ago, xsd.exe used to come as part of Visual Studio, but now it is installed with the various Microsoft Windows SDK versions (of which some are downloadable) which makes it harder to locate on your system.

The really bad thing is that Visual Studio cannot find XSD.exe as part of your project Build Events, as the PATH has not been set up correctly.

Starting xsd.exe from a Visual Studio Build Events

In my hunt for the xsd.exe location, I started with a small batch file to find the xsd.exe locations from the registry:

reg query hklm /s /f xsd.exe
reg query hkcu /s /f xsd.exe

On my current development system, it returns the keys shown below.

From that list, I decided to look for the location of “Microsoft SDKs\Windows”, but that wasn’t too helpful either.

So then I went back to see if vsvars32.bat brought me any luck: it is the batch file when you start a shortcut like these:

  • Developer Command Prompt for VS2012
  • Developer Command Prompt for VS2013

The cool thing is that the setup of Visual Studio and the various Windows SDK versions will automatically update that batch file (and the files it calls in turn) so that XSD.exe is on the path.

So now the hunt is to locate vsvars32.bat which is always in a directory that ends with  “Common7\Tools”:

reg query hkcu /s /f "\Common7\Tools\"

But that list is also too big, so I dig even further.

Within a Visual Studio build, you seem to have environment variables like these:

  • VS130COMNTOOLS for Visual Studio 14.0 (Visual Studio 2014)
  • VS130COMNTOOLS for Visual Studio 13.0 (Visual Studio 2013)
  • VS120COMNTOOLS for Visual Studio 12.0 (Visual Studio 2012)
  • VS110COMNTOOLS for Visual Studio 11.0 (Visual Studio 2010)
  • VS100COMNTOOLS for Visual Studio 10.0 (Visual Studio 2008)
  • VS90COMNTOOLS for Visual Studio 9.0 (Visual Studio 2005)
  • VS80COMNTOOLS for Visual Studio 8.0 (Visual Studio .NET 2003)

That is too cumbersome as well, especially from a Build Event and because some Visual Studio versions (like 2013) seem to define more than one of them.

However, it did point me to the $(DevEnvDir) macro. It has its share of issues though:


The final trick inside your Build Event is to call this first, before starting XSD.exe:

call "$(DevEnvDir).\..\Tools\vsvars32.bat"


References in the registry to xsd.exe

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v7.0A|bin|x64|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v7.0A|bin|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v8.0A|bin|NETFX 4.0 Tools|x64|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v8.0A|bin|NETFX 4.0 Tools|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v8.1A|bin|NETFX 4.5.1 Tools|x64|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\C:|Program Files (x86)|Microsoft SDKs|Windows|v8.1A|bin|NETFX 4.5.1 Tools|xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin/x64/xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v8.0A/bin/NETFX 4.0 Tools/x64/xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v8.1A/bin/NETFX 4.5.1 Tools/x64/xsd.exe
65EC0961132295E409600A78D649E98A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\xsd.exe.config
D6295A911E66CF6458D461A31AA0253D REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\xsd.exe
D6295A911E66CF6458D461A31AA0253D REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe
5D1DB9BEBFD84C8429B701BB74AC953B REG_SZ C:\Program Files (x86)\Microsoft.NET\SDK\v1.1\Bin\xsd.exe
41075EA44C5046841AD36815A7E7B14A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\x64\xsd.exe
65EC0961132295E409600A78D649E98A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\xsd.exe
65EC0961132295E409600A78D649E98A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\xsd.exe
41075EA44C5046841AD36815A7E7B14A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\xsd.exe
65EC0961132295E409600A78D649E98A REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\xsd.exe.config
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin/xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v8.0A/bin/NETFX 4.0 Tools/xsd.exe
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727\NGENService\Roots\C:/Program Files (x86)/Microsoft SDKs/Windows/v8.1A/bin/NETFX 4.5.1 Tools/xsd.exe

References in the registry to Microsoft SDKs

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SDKs\WindowsAzure\StorageTools\
InstallLocation REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows Azure\
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\External Tools
ToolCmd0 REG_SZ c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\guidgen.exe
ToolDir0 REG_SZ c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\External Tools\Create GUID
ToolCmd REG_SZ c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\guidgen.exe
ToolDir REG_SZ c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
InstalledPath REG_SZ C:\Program Files (x86)\Microsoft SDKs\Windows Azure\Mobile Services\1.0\ProjectTemplate\



3 Responses to “Finding the path of xsd.exe from your Visual Studio Build Events”

  1. […] via: Finding the path of xsd.exe from your Visual Studio Build Events « The Wiert Corner – irregular s…. […]

  2. Marjan said


    vsvars32.bat, hey? sounds a lot like rsvars??.bat. :D

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: