VCProjectEngineObject Samples

The VCProjectEngineObject samples illustrate how to programmatically modify a Visual C++ project. The sample shows how to do the following:

  • Create a new instance of the VCProjectEngine object and use it to load an existing Visual C++ project for modification.

  • Use the VCProject object to change the project name and add a new configuration to the project.

  • Use the VCConfiguration object to get the debug configuration from the project and change the project type from a dynamic-link library (.dll) to an application (.exe).

  • Get the linker tool from the configuration and use the VCLinkerTool object to change the Show Progress property from the default Not Set to Display All Progress Messages.

  • Use the AddFile method to add a .cpp file to the project.

  • Use the IVCCollection object to enumerate to the existing .cpp file, access the file level release configuration, get the compiler tool associated with the file, and change the Optimization property to Full Optimization.

  • Save the project to a different .vcproj file.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

Versions of the Sample

The sample is available for the following languages:

Building and Running the Sample

The target project file (Myproject.vcproj) will be modified by the sample and saved to a new file (MyProjectNew.vcproj). To facilitate an easy return to the starting state for further exploration and subsequent runs, make copies of the target project files before running the sample.

Also, prior to running the sample, open MyProject.vcproj and open the Property Pages dialog box to examine its properties.

To build and run the Visual C++, Visual C#, or Visual Basic .NET sample

  1. Open the solution file for the desired language project.

  2. From the Build menu, click Build.

  3. Copy the Sample.exe file in the build output directory to the MyProject subdirectory. For the Visual C# and Visual Basic samples, you also need to copy Interop.VCProjectEngineLibrary_1_0.dll to the MyProject subdirectory.

  4. From the command prompt in the MyProject subdirectory, type Sample.

To build and run the sample in JScript

  1. Copy the project sample.js file to the MyProject subdirectory.

  2. From the command prompt in the MyProject subdirectory, type cscript sample.js.

After running the sample, observe and compare the changes made and saved to MyNewProject.vcproj. The changes are that the project name has been changed to Voila, a new configuration has been added, and the New.cpp file has been added to the project.

In addition, the following properties have been modified in the Property Pages dialog box:

  • Show Progress property (Linker folder, General page)

  • Optimization property (C/C++ folder, Optimization page)

Sample Files

The files for each language are:

Language

Files

Visual C++

Sample.vcproj and Sample.cpp

Visual C#

Sample.csproj, Sample.csproj.user, Assemblyinfo.cs, and Class1.cs

JScript

Sample.js

Visual Basic .NET

Sample.vbproj, Sample.vbproj.user, and Module1.vb

The target project contains the following files:

  • MyProject.vcproj – The project file.

  • New.cpp – The file to be added.

  • Existing.cpp – The file whose property is to be modified.

Keywords

This sample demonstrates the following keywords:

VCProjectEngineObject; VCProject; VCConfiguration; VCLinkerTool; AddFile; IVCCollection

See Also

Other Resources

Project Model Samples