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 1,565 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:

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:

Solution

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

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

–jeroen

References in the registry to xsd.exe

References in the registry to Microsoft SDKs

 

 

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

    nice.

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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

 
%d bloggers like this: