Skip to content

Instantly share code, notes, and snippets.

@h-sao
Created May 10, 2011 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-sao/964083 to your computer and use it in GitHub Desktop.
Save h-sao/964083 to your computer and use it in GitHub Desktop.
VMware vSphere Web Services SDK 4.1 for Visual Studio 2010(Windows7 64bit) from a command prompt
@setlocal
@echo off
@rem generates and compiles the .NET proxy classes and precompiled XmlSerializers
@rem and builds all the C# samples in debug mode.
@rem The name of the assemblies to generate. They should have a "2008" suffix
@rem if the samples are to be built automatically.
@rem
@set FILE_VIMSERVICE=VimService2008
@set FILE_VIM25SERVICE=Vim25Service2008
@if not defined USEDOTNET35 (
@if DOTNET35==%1DOTNET35 (
@set USEDOTNET35=0
) else (
@set USEDOTNET35=%1
)
)
@echo USEDOTNET35="%USEDOTNET35%"
@if not defined WSDLFILE (
@set WSDLFILE="..\..\wsdl"
)
@echo WSDLFILE="%WSDLFILE%"
@if %USEDOTNET35%==1 (
@set PATH=%WINDIR%\Microsoft.NET\Framework\v3.5;"%ProgramFiles%\Microsoft SDKs\Windows\v7.1\bin";"%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin";"%ProgramFiles%\Microsoft SDKs\Windows\v7.0\bin";"%ProgramFiles%\Microsoft SDKs\Windows\v6.1\bin";%PATH%
) else (
@set PATH=%WINDIR%\Microsoft.NET\Framework\v4.0.30319;"%ProgramFiles%\Microsoft SDKs\Windows\v7.1\bin\NETFX 4.0 Tools";"%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools";"%ProgramFiles%\Microsoft SDKs\Windows\v7.0\bin\NETFX 4.0 Tools";%PATH%
)
rem change to batch file directory and drive
call :get_cur_drive %CD%
%~d0
pushd %~p0
@rem generate optimized stubs and precompiled serializer dll for the VIM wsdl files
@rem and a DLL containing the optimized stubs named VimService2010.dll, and
@rem a DLL containing precompiled XmlSerializers named VimService2010.dll
@rem See the text document GeneratingStubs.txt for more information on this utility
@call genvimstubs2010.cmd %WSDLFILE%\vim VimApi stage VimObjects.cs . %FILE_VIMSERVICE%
@call genvimstubs2010.cmd %WSDLFILE%\vim25 Vim25Api stage VimObjects.cs . %FILE_VIM25SERVICE%
@if %USEDOTNET35%==1 (
@echo Building Samples in Debug mode
msbuild cs\Samples2008.sln
)
@echo Done Building optimized Stubs and all Samples
goto end
:end
popd
%CDRIVE%
set CDRIVE=
goto :EOF
:get_cur_drive
set CDRIVE=%~d1
@endlocal
@setlocal
@echo off
@rem Generate WebService Stubs and precompiled stub serializers
@rem This script takes 6 parameters
@rem 1. directory of wsdl files. This is a mandatory parameter.
@rem 2. namespace for stubs
@rem This defaults to VimApi
@rem 3. stub output directory
@rem This defaults to .
@rem 4. output filename
@rem This defaults to VimObjects.cs
@rem 5. dll directory
@rem This defaults to .
@rem 6. Name of the DLLs to generate.
@rem This defaults to VimService2008*
@rem this script assumes that the files are named vim.wsdl and vimservice.wsdl
@if [%1]==[] goto err_no_WSDLFILE
@if not exist %1\vim.wsdl goto err_no_WSDLFILE
@if not exist %1\vimService.wsdl goto err_no_WSDLFILE
@set _WSDLDIR=%1
@if [%2]==[] (
@set _NAMESPACE=VimApi
) else (
@set _NAMESPACE=%2
)
@if [%3]==[] (
@set _STUBDIR=.
) else (
@set _STUBDIR=%3
)
@if [%4]==[] (
@set _STUBFILENAME=VimObjects.cs
) else (
@for /f "tokens=1" %%G in ('echo %~n4') do (
@set _STUBFILENAME=%%G
@call :set_filename %%G
)
@goto done_setfilename
:set_filename
@set _STUBFILENAME=%1.cs
@goto :eof
:done_setfilename
@set dummy=
)
@if [%5]==[] (
@set _DLLDIR=.
) else (
@set _DLLDIR=%5
)
@if [%6]==[] (
@set _DLLNAME=VimService2008
) else (
@set _DLLNAME=%6
)
@set _LASTPASS=no
@if "%_STUBDIR%"=="." goto create_dll_dir
echo Checking and Creating %_STUBDIR%
@if not exist %_STUBDIR% (
@rd /s/q %_STUBDIR%
@if exist %_STUBDIR% (
@rd /s/q %_STUBDIR%
)
)
@md %_STUBDIR%
:create_dll_dir
@if "%_DLLDIR%"=="." goto gen_vim_stubs
echo Checking and Creating %_DLLDIR%
@if not exist %_DLLDIR% (
@rd /s/q %_DLLDIR%
@if exist %_DLLDIR% (
@rd /s/q %_DLLDIR%
)
)
@md %_DLLDIR%
:gen_vim_stubs
@rem generate the Vim C# stub file
@if "%_WSDLDIR:~-2%"=="25" (
echo VIM25 %_NAMESPACE% %_WSDLDIR%
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\wsdl.exe" /l:CS /n:%_NAMESPACE% /out:%_STUBDIR%\%_STUBFILENAME% %_WSDLDIR%\vim.wsdl %_WSDLDIR%\vimService.wsdl %_WSDLDIR%\core-types.xsd %_WSDLDIR%\query-types.xsd %_WSDLDIR%\query-messagetypes.xsd %_WSDLDIR%\vim-types.xsd %_WSDLDIR%\vim-messagetypes.xsd
) else (
echo VIM2 %_NAMESPACE% %_WSDLDIR%
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\wsdl.exe" /l:CS /n:%_NAMESPACE% /out:%_STUBDIR%\%_STUBFILENAME% %_WSDLDIR%\vim.wsdl %_WSDLDIR%\vimService.wsdl
)
@rem compile the stub dll
:compile_DLL
"C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe" /t:library /out:%_DLLDIR%\%_DLLNAME%.dll %_STUBDIR%\%_STUBFILENAME%
@if "%_LASTPASS%"=="yes" goto end_ok
@rem use sgen tool to pre-generate and compile Xml Serializers
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sgen.exe" /force /p /out:%_DLLDIR% %_DLLDIR%\%_DLLNAME%.dll
@rem comment out all [System.Xml.Serialization.XmlIncludeAttribute lines
@echo Optimizing generated stubs...
OptimizeWsStubs.exe %_STUBDIR%\%_STUBFILENAME% %_DLLNAME%
@set _LASTPASS=yes
goto compile_DLL
:err_no_STUBDIR
@echo Error: Directory to build stubs in %_STUBDIR% does not exist
goto end_err
:err_no_DLLDIR
@echo Error: Directory to compile DLLs in %_DLLDIR% does not exist
goto end_err
:err_no_WSDLFILE
@echo Error: Directory for WSDL files vim.wsdl and vimService.wsdl not specified
@echo Please specify WSDL files to generate stubs for
@echo Run As: genvimstubs.cmd <WSDL Directory> [<Stub Namespace>] [<Stub file output directory>] [<Stub filename with .cs>] [<Dll output directory>] [<Stub Dll name(without .dll extension)>]
@echo E.g.
@echo genvimstubs.cmd .\
@echo Or to customize namespace stubfilename and dll names etc...
@echo genvimstubs.cmd .\ VimApi .\stubdir MyVimStubs.cs .\dlldir MyVimStubs
@echo
:end_err
@echo Stub generation Failed!
@echo
goto end
:end_ok
@echo Stub generation Done.
@echo
:end
@endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment