Building Applications that Use the Windows SDK
This document describes how to use either the Windows SDK Command Prompt window or Visual Studio to configure application build settings for use with native code projects and managed code projects. It also describes how to upgrade Visual C++ projects that use the .vcproj file format so that they can use MSBuild.
The Windows SDK for Windows 7 and the .NET Framework 4 (later referred to as the Windows SDK) includes compilers that let you build Visual C++, Visual C#, and Visual Basic applications. You can use these compilers directly or use the nmake tool to use these compilers from a makefile. You can also use MSBuild to build Visual C++ (.vcxproj), Visual C# (.csproj) and Visual Basic (.vbproj) projects or Visual Studio solutions (.sln).
The following table provides links to more information about how to use the compilers and build tools to create Visual C++, Visual C#, and Visual Basic applications.
Describes the Microsoft Build Engine (MSBuild) and how to use it to build projects and solutions.
Demonstrates how to use the Visual C++ compiler, cl.exe, to compile a Visual C++ application.
Describes how to use the Visual C# compiler, csc.exe, to compile Visual C# applications.
Describes how to use the Visual Basic compiler, vbc.exe, to compile Visual Basic applications.
Describes makefiles and the nmake tool.
If you do not have Visual Studio 2010, you can use the Windows SDK Command Prompt window and the SetEnv utility to configure your application build settings. The SetEnv utility lets you build applications for a specific operating system and computer architecture. The default settings target the operating system on which the Windows SDK is installed.
To open the Windows SDK Command Prompt window, click Start, then All Programs, then Microsoft Windows SDK v7.1, and then Windows SDK 7.1 Command Prompt. At the command prompt, run the SetEnv utility to configure the build environment for a specific operating system, computing architecture, or build configuration. The SetEnv utility uses the following syntax:
SetEnv.cmd [/Debug | /Release] [/x86 | /x64 | /ia64] [/vista | /xp | /2003 | /2008 | /win7] [-h | /?]
The following command configures the build environment to create 64-bit Windows 7 applications that use the Debug build configuration:
SetEnv.cmd /Debug /x64 /win7
SetEnv configures the build environment to create Windows 7 applications by default if you do not specify the operating system.
The following table describes the SetEnv options. Options that create applications for a specific operating system apply only to the nmake utility.
Create a Debug configuration build environment.
Create a Release configuration build environment.
Create 32-bit x86 applications.
Create 64-bit x64 applications.
Create 64-bit Itanium applications.
/vista (nmake specific)
Create Windows Vista applications.
/xp (nmake specific)
Create Windows XP SP2 applications.
/2003 (nmake specific)
Create Windows Server 2003 applications.
/2008 (nmake specific)
Create Windows Server 2008 or Windows Vista SP1 applications.
/win7 (nmake specific)
Create Windows 7 applications.
Display command usage.
The Windows SDK provides headers and libraries for creating Windows applications that use native code. These are the same as those that come with Visual Studio 2010, except that the Windows SDK provides newer versions of some tools.
The following sections describe how to configure Visual Studio 2010 and Visual Studio 2008 to use the headers, libraries, and tools that are included in the Windows SDK.
Using the Windows SDK Tools with Visual Studio 2010
To use the Windows SDK tools in Visual Studio 2010
In Visual Studio 2010, open a solution (.sln) file or create a solution.
In Solution Explorer, right-click the project node and then click Properties.
In the Configuration list, select All Configurations.
Under Configuration Properties, select General.
As the Platform Toolset option, select Windows7.1SDK.
Using the Windows SDK Tools with Visual Studio 2008
You can use the Windows SDK Configuration Tool to configure the Windows SDK for use with Visual Studio 2008. The following steps describe how to use the Windows SDK Configuration Tool in the Visual Studio 2008 user interface and in the Windows SDK Command Prompt window.
To use the Windows SDK Configuration Tool in Visual Studio 2008
Start the Windows SDK Configuration Tool by clicking Start, then All Programs, then Microsoft Windows SDK v7.1, and then Visual Studio Registration.
Right-click Windows SDK Configuration Tool and then click Run as administrator.
In the Windows SDK Configuration Tool, in the list, select v7.1.
Click Make Current.
To use the Windows SDK Configuration Tool in the Windows SDK Command Prompt window
Open the Windows SDK Command Prompt window by clicking Start, then All Programs, then Microsoft Windows SDK v7.1, and then Windows SDK 7.1 Command Prompt.
Navigate to the ..\ Windows SDK installation folder\Setup\ folder, for example, C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\.
Type WindowsSdkVer.exe -version:v7.1.
Upgrading Projects to Visual C++ 2010
For Visual C++ projects, MSBuild 4.0 works with the Visual C++ 2010 project file format, .vcxproj. This section describes how to upgrade Visual C++ projects that use the earlier .vcproj format so that they use the .vcxproj format.
If you have Visual Studio 2010, you can use devenv.exe and the /upgrade option to upgrade earlier projects to the current format. For more information about the /upgrade option, see /Upgrade (devenv.exe). Otherwise, you can use the vcupgrade tool to upgrade earlier projects. The vcupgrade tool works on project files from Visual Studio 2005 and Visual Studio 2008.
You can use the vcupgrade tool in the Windows SDK Command Prompt window, which you can open by clicking Start, then All Programs, then Microsoft Windows SDK v7.1, and then Windows SDK 7.1 Command Prompt. The following command uses vcupgrade to upgrade a project named Hello.vcproj to use the .vcxproj format:
This command produces Hello.vcxproj as its output. You can then use MSBuild to build the project, as shown in the following example:
MSBuild.exe Hello.vcxproj /t:Rebuild /p:Configuration=Debug
If your solution contains multiple Visual C++ projects, you must run vcupgrade on each Visual C++ project to upgrade it to the .vcxproj file format. In addition, when you use vcupgrade to upgrade a project to the .vcxproj file format, vcupgrade does not update the corresponding solution (.sln) file. Therefore, you must specify the upgraded projects and not the solution file when you use MSBuild.
Working with 64-bit Visual C++ Projects
You can use the Visual C++ 64-bit compiler to target 64-bit computing architectures. Many of the Windows SDK sample projects also support 64-bit. For information about how to configure Visual C++ projects to target 64-bit operating systems and how to troubleshoot common Visual C++ 64-bit migration issues, see 64-Bit Programming with Visual C++.