Search

Unexpected exception when setting CommandLine property of VCCustomBuildTool by fnqbruce

Active

1
0
Sign in
to vote
Type: Bug
ID: 776854
Opened: 1/17/2013 5:57:26 PM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
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.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

1. New Project. Templates/Visual C++/General. CustomWizard. OK.

2. In the Custom Wizard, accept all defaults and click Finish.

3. Open default.js.

4. In line 16 (the line after "PchSettings(selProj);") insert a new line:

        CustomFileSettings(selProj);

5. At line 125 (after the implementation of PchSettings()), insert the new method:

function CustomFileSettings(proj) {
    try
    {
        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...';
    }
    catch(e)
    {
        throw e;
    }
}

6. Save the changes to default.js.

7. Press F5 to debug the wizard.

8. In the new instance of Visual Studio 2012, create a new project of type Wizard1 (or whetever the name of your wizard is).

9. In the Wizard, click Finish. The following exception may occur:

Mismatched PageRule with the wrong ItemType.

10. If the exception does not occur, repeat steps 8 & 9, until it does. Sometimes as many as 5 repetitions are required until it occurs.


Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

An exception is raised when a tool's property is set immediately after setting the file's ItemType to "CustomBuild".

Expected results

The tool's property is set - and later appears on the property pages for the file.
File Attachments
File Name Submitted By Submitted On File Size  
default_js.zip 1/17/2013 1 KB
Sign in to post a comment.
Posted by Microsoft on 1/18/2013 at 2:35 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 1/17/2013 at 6:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by fnqbruce on 1/19/2013 at 11:48 PM
// A work-around is available as follows.


function CustomFileSettings(proj) {
    try
    {
        var config = proj.Object.Configurations('Debug');
        var file = proj.Object.Files('Sample.txt');
        var projectTool = config.Tools('VCCustomBuildTool');
        file.ItemType = 'CustomBuild';
        
        // Save, close and reopen the project
        proj.Save();
        var prjPath = proj.FullName;
        dte.Solution.Remove(proj);
        proj = dte.Solution.AddFromFile(prjPath, false);
        
        // Reinitialize all object model handles, since they are no longer valid
        file = proj.Object.Files('Sample.txt');
        var fileConfig = file.FileConfigurations('Debug');
        var tool = fileConfig.Tool;
        tool.CommandLine = 'ECHO Custom build...';
    }
    catch(e)
    {
        throw e;
    }

    // Return the new project reference, for use by the calling function
    return proj;
}