locked
Set the BuildAction of a document RRS feed

  • Question

  • I am currently trying to set the BuildAction of files which are in a project. Additionally I really want to avoid the use of `BrowseObject`'s and the DTE. So I ended up with the following:
    public void SetBuildAction(string buildAction)
    {
        ThreadHelper.ThrowIfNotOnUIThread();
    
        var result = Hierarchy.SetProperty(ItemId, (int)__VSHPROPID4.VSHPROPID_BuildAction, buildAction);
    
        ErrorHandler.ThrowOnFailure(result);
    }
    However, the method is returning me a the following error code:
    DISP_E_MEMBERNOTFOUND -2147352573
    
    A return value indicating that the requested member does not exist, or the call to Invoke tried to set the value of a read-only property.
    Since the `GetProperty` method with the same `propId` works as expected, I suspect that this property is read-only. I know for a fact that you can change this value and you are even allowed to by the user, so how comes? Is there any alternative?
    Saturday, March 21, 2020 2:15 AM

All replies

  • Hi 24_minutes,

    Welcome to MSDN forum.

    Could you share some details about the "buildAction" parameter? Maybe you can try to use prjBuildAction Enum as parameter, which is like:

    prjBuildAction[] buildActions = new prjBuildAction[4];
    var result = Hierarchy.SetProperty(ItemId, (int)__VSHPROPID4.VSHPROPID_BuildAction, buildActions[0]);

    BTW, I found some samples about using VsHierarchy.SetProperty, hope it could help you.

    Best Regards,

    Dylan

     

    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. 

    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, March 23, 2020 4:04 AM
  • Sadly none of the samples helped me.

    The `buildAction` parameter contains the literal name of the action e.g. "None" ..., I took the value from the GetProperty method and passing it the same propId.

    Additionally, as the documentation tells, it is a `BSTR` e.g. a string, so your example wouldn't work.
    • Edited by 24_minutes Tuesday, March 24, 2020 1:28 AM
    Tuesday, March 24, 2020 1:24 AM
  • Hi 24_minutes,

    Thanks for your reply.

    About this error, this may be because the method can't find the corresponding variant for your string "buildAction". You could try "buildActions[0].tostring()".

    Best Regards,

    Dylan



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, March 26, 2020 10:26 AM
  • The DISP_E_MEMBERNOTFOUND error indicates that the underlying project type (which you haven't identified) doesn't support that particular property (VSHPROPID_BuildAction). It sounds like the alternative is to use the automation interface.

    Sincerely,


    Ed Dore

    Thursday, March 26, 2020 6:08 PM
  • That's sad, thanks anyway!
    Tuesday, March 31, 2020 12:44 AM