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 4,152 other subscribers

Batch file: Finds the location of xsd.exe by running the vsvars32.bat of the youngest installed Visual Studio

Posted by jpluimers on 2015/05/12

Boy, Microsoft made it hard to find the location of xsd.exe!

It is actually located like here:

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe

But that is nowhere on the default path, nor in the registry.

What happens during installation of Visual Studio and/or the Microsoft SDK, is that the vsvars32.bat file of Visual Studio is updated so it can add the location of many tools (including xsd.exe) to the PATH.

So the trick is to find the youngest Visual Studio first, then run the according vsvars32.bat, and then xsd.exe is on the path.


:: Dynamically finds the installed xsd.exe, then calls it with the passed parameters
:: test these environment variables that have 110 or 120 in them (future enhancements: support more Visual Studio versions):
:: Visual Studio .NET 2002: VS70COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio .NET\Common7\Tools\
:: Visual Studio .NET 2003: VS71COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Common7\Tools\
:: Visual Studio 2005: VS80COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\
:: Visual Studio 2008: VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\
:: Visual Studio 2010: VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
:: Visual Studio 2012: VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
:: Visual Studio 2013: VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
:: They contain `vsvars32.bat` which will update the `PATH` so it includes where `xsd.exe` resides
setlocal enabledelayedexpansion
:: delayed expansion allows for the exclamation marks
:: see http://ss64.com/nt/delayedexpansion.html
:: see http://stackoverflow.com/questions/22857407/windows-batch-how-to-assign-variable-with-dynamic-name
for %%v in (70 71 80 90 100 110 120 130) do if not [!VS%%vCOMNTOOLS!]==[] set VSCOMNTOOLS=!VS%%vCOMNTOOLS!
call :do call "!VSCOMNTOOLS!vsvars32.bat"
call :do where xsd.exe
xsd.exe %*
endlocal
goto :eof
:do
echo %*
%*
goto :eof

view raw

Run-Xsd.exe.bat

hosted with ❤ by GitHub

–jeroen

via:

Code:

  :: Dynamically finds the installed xsd.exe, then calls it with the passed parameters

  :: test these environment variables that have 110 or 120 in them (future enhancements: support more Visual Studio versions):
  :: VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
  :: VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
  :: They contain `vsvars32.bat` which will update the `PATH` so it includes where `xsd.exe` resides
  setlocal enabledelayedexpansion
  :: delayed expansion allows for the exclamation marks
  :: see http://ss64.com/nt/delayedexpansion.html
  :: see http://stackoverflow.com/questions/22857407/windows-batch-how-to-assign-variable-with-dynamic-name
  for %%v in (110 120) do set VSCOMNTOOLS=!VS%%vCOMNTOOLS!
  call :do call "!VSCOMNTOOLS!vsvars32.bat"
  call :do where xsd.exe
  xsd.exe %*
  endlocal
  goto :eof

:do
  echo %*
  %*
  goto :eof

One Response to “Batch file: Finds the location of xsd.exe by running the vsvars32.bat of the youngest installed Visual Studio”

  1. Reblogged this on Dinesh Ram Kali..

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 )

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: