locked
How to set the PostBuildEvent programmatically RRS feed

  • Question

  • Hi

    I'm trying to setup the PostBuildEvent of a C++ project programmatically (from C#) but I'm getting the following exception:

    {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"}

    Here's my code:

    private void AddBuildevent(object inputParams)
            {
                ArrayList Inputs = inputParams as ArrayList;
                Project pExisting = Inputs[0] as Project;
                object[] buildEvents = Inputs[1] as object[];
                using (new VMessageFilter())
                {
                    VSProject oProj = pExisting.Object as VSProject;
                    string buildEvent = buildEvents[1].ToString();
                    try
                    {
                        oProj.Project.Properties.Item("PostBuildEvent").Value = buildEvents;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }



    Monday, July 25, 2016 5:42 PM

Answers

  • Thank you Carlos and cole for your answers.

    I created a small sample to illustrate the issue but the sample worked as expected!

    The only difference between the sample and my application was that the sample was referencing version 14.0.0.0 of VCProjectEngine, VCProject and VCCodeModel whereas my application was referencing version 10.0.0.0.

    When I changed my application to version 14.0.0.0, everything worked perfectly.

    Thank you for taking the time to answer my question. Much appreciated.


    Ralph Michel

    • Proposed as answer by DotNet Wang Saturday, July 30, 2016 7:24 AM
    • Marked as answer by DotNet Wang Saturday, July 30, 2016 7:25 AM
    Thursday, July 28, 2016 11:20 AM

All replies

  • Rectification, the line:

    oProj.Project.Properties.Item("PostBuildEvent").Value = buildEvents;

    should have been:

    oProj.Project.Properties.Item("PostBuildEvent").Value = buildEvent;

    but I get the same error in both cases.

    Any help would be much appreciated.

    Ralph


    Monday, July 25, 2016 5:46 PM
  • I changed the code to:

    try { Property postBuildEvent = oProj.Project.Properties.Item("PostBuildEvent"); // <- same exception postBuildEvent.Value = buildEvent; } catch (Exception ex) { Console.WriteLine(ex.Message); }

    and now I get an exception at the line that sets the postBuildEvent property:

    {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"}


    Monday, July 25, 2016 7:21 PM
  • Hi RalphMichel,

    Could you please provide a complete code snippet or a simple demo which could reproduce the issue. we'll reproduce your issue on our side and try to find a solution to resolve it.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 27, 2016 9:08 AM
  • Hi,

    For C++ you would need to use the C++ automation model for projects (VCProjectEngine) and specifically the VCPostBuildEventTool interface:

    https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vcpostbuildeventtool.aspx

    Notice that the PostBuild tool depends on the project configuration, so it is not a property of a project.

    I am busy now to create a sample for VCPostBuildEventTool but this other one that I created long time ago for the VCCLCompilerTool should help you:

    HOWTO: Get additional include directories of Visual C++ project from an add-in
    http://www.mztools.com/articles/2014/MZ2014005.aspx




    My portal and blog about VSX: http://www.visualstudioextensibility.com
    Twitter: https://twitter.com/VSExtensibility
    MZ-Tools productivity extension for Visual Studio: http://www.mztools.com

    Thursday, July 28, 2016 11:06 AM
  • Thank you Carlos and cole for your answers.

    I created a small sample to illustrate the issue but the sample worked as expected!

    The only difference between the sample and my application was that the sample was referencing version 14.0.0.0 of VCProjectEngine, VCProject and VCCodeModel whereas my application was referencing version 10.0.0.0.

    When I changed my application to version 14.0.0.0, everything worked perfectly.

    Thank you for taking the time to answer my question. Much appreciated.


    Ralph Michel

    • Proposed as answer by DotNet Wang Saturday, July 30, 2016 7:24 AM
    • Marked as answer by DotNet Wang Saturday, July 30, 2016 7:25 AM
    Thursday, July 28, 2016 11:20 AM