Building Samples from the Samples Directory
Microsoft .NET Framework samples are found individually in the SDK documentation. From each sample page, download the sample files to a chosen location. The .NET Framework samples can also be accessed in bulk by directly opening the sample .zip files located in %MSSDK%\Samples. Win32 samples are installed as loose files in subdirectories of \Program Files\Microsoft SDKs\Windows\v6.1\Samples.
How to build samples from the Samples directory
Copy the sample to a working folder not under \Program Files. Copying to a location other than Program Files makes it possible to maintain a pristine copy of the SDK samples and avoid issues when writing to files and directories located under Program Files.
Open the Windows SDK CMD shell (Start > All Programs > Windows SDK v6.1 > SDK CMD Shell).
Navigate to the sample directory.
Build the sample from the command line as follows (where ‘*’ is the filename):
Build a makefile by typing nmake
Build a .csproj file by typing msbuild *.csproj /p:platform=[win32 | X64 | IA64]
Build a .vbproj file by typing msbuild *.vbproj /p:platform=[win32 | X64 | IA64]
Build a .sln file by typing msbuild *.sln /p:platform=[win32 | X64 | IA64]
Build a .vcproj by typing vcbuild *.vcproj /platform=[win32 | X64 | IA64]
To build samples in the SDK build environment or in Microsoft Visual Studio 2008, some samples project files must be upgraded. This step is not necessary when building in Visual Studio 2005. The compilers in the SDK are VC 9.0, the same compilers that ship in Microsoft Visual Studio 2008. The sample project files in the SDK are written for VC 8.0 compilers, the compilers that ship in Microsoft Visual Studio 2005.
In the SDK Build environment, type vcbuild /upgrade' or 'devenv /upgrade to upgrade the project.
Microsoft .NET Framework sample project files cannot be upgraded using the workaround above. The files must be upgraded using vcbuild /upgrade /overrideRefVer SampleName.vcproj. The upgrade /overriderefver switch indicates that it will use the .NET Framework.
To utilize Windows SDK headers, libraries, and tools within Microsoft Visual Studio 2005, the Windows SDK Configuration tool must first be run. This step is not necessary with Microsoft Visual Studio 2008. The SDK Configuration Tool must be run for each user on Windows Vista or Windows Server 2008. To run the Microsoft Visual Studio 2005 Registration Tool, go to Start >All Programs >Microsoft Windows SDK v6.1 > Visual Studio Registration >Windows SDK Configuration Tool (on Windows Vista or Windows Server 2008, right-click and select Run as Administrator).
You can use the switches shown below to target different operating systems from within the SDK build environment. To target Windows Vista, you should use the /vista switch. To target Windows Vista SP1, you should use the /2008 switch. Launch the Windows SDK build environment (Start > All Programs > Microsoft Windows SDK v6.1 > CMD Shell) and change directories to the \Bin folder. At the prompt, type setenv /[desired OS switch]
C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin>setenv /?
Usage: Setenv [/Debug | /Release][/x86 | /x64 | /ia64][/vista | /xp | /2003 | / 2008 ][-h or /?]
/Debug - Create a Debug configuration build environment
/Release - Create a Release configuration build environment
/x86 - Create 32-bit x86 applications
/x64 - Create 64-bit x64 applications
/ia64 - Create 64-bit IA64 applications
/vista - Windows Vista applications
/xp - Create Windows XP SP2 applications
/2003 - Create Windows Server 2003 applications
/2008 - Create Windows Server 2008 or Windows Vista SP1 applications