Monday, November 29, 2010

How to develop your own VMWare application in C#

First, download and install "Visual Studio Express 2008" (http://www.microsoft.com/express/Downloads/)
Then download and install "VMware vSphere Web Services SDK" (http://www.vmware.com/download/sdk/)

In file Build2008.cmd (from your "VMware vSphere Web Services SDK directory\samples\DotNet" directory) if you installed your VS2008 Express in an other directory than default directory modify line
set VSINSTALLDIR="C:\Program Files\Microsoft Visual Studio 9.0"

Run a command line prompt.

Verify in command line prompt you can run
- WSDL.exe (by default at C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin)
- csc.Exe (by default at C:\WINDOWS\Microsoft.NET\Framework\v3.5)
- VCSExpress.exe (by default at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE)

Else add path of these programs with something like this in command line before running Build2008.cmd:
Set path=%path%;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

In command line prompt do not forget to run this line too:
set WSDLFILE=your VMware vSphere Web Services SDK directory\wsdl

Then run Build2008.cmd
You should have all your .dll libraries created.

Run in your VMware vSphere Web Services SDK directory\samples\DotNet\cs\SimpleClient\bin\Debug this line to verify all is ok:
SimpleClient.exe https://yourvc/sdk yourvcuser yourvcpassword

Now, if you need to create your own application, just add line
using Vim25Api;
and in your project "add reference" tab browse
"Vim25Service2008.dll" and "Vim25Service2008.XmlSerializers.dll"

Use examples in your vSphere Web Services SDK\directory\samples\DotNet\cs for helping you to create your 1st C# vmware application

3 comments:

releasethegrip said...

Thank you so much for this information! I just wanted to add that Build2008.cmd wasn't working for me on my 64 bit machine because visual studio was installed in program files (86) directory which caused build2008.cmd to fail with \microsoft unexpected error. I had to edit it to get rid of all the parenthesis.

releasethegrip said...

like this:

@if not defined VSINSTALLDIR goto SETVSDIR


:SETVSDIR
@echo Setting vsinstalldir
@set VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0
:end

if exist %VSINSTALLDIR%\Common7\IDE\VCSExpress.exe goto SETDEVENV

if exist %VSINSTALLDIR%\Common7\IDE\devenv.exe goto SETDEVENV2

if not exist %VSINSTALLDIR%\Common7\IDE\devenv.exe goto err_NO_DEVENV

:SETDEVENV
@echo Visual Studio C# 2008 Express is installed
@set VSINSTALLDIR=C:\Program Files (86)\Microsoft Visual Studio 9.0
@set DEVENV=VCSExpress.exe
:end

:SETDEVENV2
@echo Visual Studio 2008 is installed
@set DEVENV=devenv.exe

:end

@if not defined FrameworkDir goto FRAMEDIR

:FRAMEDIR
@echo Setting Path
@rem set PATH to use VCSExpress.exe or VisualStudio's Devenv.exe
@rem Assumes .NET is installed in the default location.
@set PATH=%PATH%;%VSINSTALLDIR%\Common7\IDE
@set PATH=%PATH%;%VSINSTALLDIR%\SDK\v3.5\Bin

@rem Assumes that .NET 3.5 is installed in the default location
@set PATH=%PATH%;%WINDIR%\Microsoft.NET\Framework\v3.5

@rem for Visual Studio 2008, and Visual C# 2008 Express,
@rem INCLUDE, LIB and LIBPATH are not required
@rem since we're only building C# samples
@set INCLUDE=
@set LIB=
@set LIBPATH=
:end

rem change to batch file directory and drive
call :get_cur_drive %CD%
%~d0
pushd %~p0

@echo Done Building optimized Stubs and all Samples
goto end

:err_no_DEVENV
@echo Error: No .NET Development environment or tools found installed
@echo Visual Studio 2008 or Visual C# 2008 Express must be installed
@echo -
@echo If you have Visual Studio 2008 installed, please run this from
@echo a Visual Studio 2008 Command Prompt.
@echo -
@echo If you have Visual C# 2008 Express and it is not installed in the
@echo default location "C:\Program Files\Microsoft Visual Studio 8",
@echo then please set the environment variable VSINSTALLDIR to the
@echo directory that contains the 2 directories "Common7" and "SDK"
@echo e.g. if Visual Studio is installed in the directory "All My Apps"
@echo set VSINSTALLDIR="C:\All My Apps\Microsoft Visual Studio 8"
@echo -
@echo Please use quotes around directory names with spaces in them.

:end
popd
%CDRIVE%
set CDRIVE=
goto :EOF

:get_cur_drive
set CDRIVE=%~d1
@endlocal

Franck RICHARD said...

Thanks for your report. You can also add these lines to work in both x86 and x64 environment

set Pfiles=%ProgramFiles(x86)%
if "%ProgramFiles(x86)%"=="" (
set Pfiles=%ProgramFiles%
)
echo %pfiles%

then use %pfiles% instead of program files (x86)