In a custom VC++ project wizard, immediately after setting a file's ItemType to 'CustomBuild', any attempt to set any of the properties of the CustomBuildTool will result in an exception: "Mismatched PageRule with the wrong ItemType."
For example, in the code below, the last line will usually cause the exception:
var config = proj.Object.Configurations('Debug');
var file = proj.Object.Files('Sample.txt');
var projectTool = config.Tools('VCCustomBuildTool');
file.ItemType = 'CustomBuild';
var fileConfig = file.FileConfigurations('Debug');
var tool = fileConfig.Tool;
tool.CommandLine = 'ECHO Custom build...';
A variety of techniques may prevent the exception, including:
- Using the debugger
- Adding a sleep between setting file.ItemType and setting the CommandLine property
- Creating a log file using FileSystemObject and writing to it before setting the CommandLine property
However, only using the debugger reliably prevents the exception.
Please note that this problem does not occur in Visual Studio 2010.