Answered Working with a DTE.Project and an MSBuild Project

  • Tuesday, May 02, 2006 2:03 PM
     
     

    I'm working on an automation project that does a bunch of work with a DTE Project, and for the most part, the DTE Project exposes everything I need....

    Except for the "internal" settings of the project file itself, ie - the info contained within:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    .... blah blah blah...
    </PropertyGroup>

    On the other hand, instantiating an MSBuild Project allows me to go after and play with all the underlying goodness using the GetEvaluatedProperty() and SetProperty() methods. 

    My dilemna is trying to save any changes I made via the MSBuild project - as you would expect, the VS IDE advises me that something (ie: the MSBuild Project) has changed my project outside the environment, and "would I like to reload"?  This is causing havoc on my automation logic. 

    Is there a way I can manipulate the data within this property group (using MSBuild or other) without having the IDE get upset (ie: can I somehow effect the change using the DTE.Project?)

    Following is some sample code:

    private void PlayWithProjectStuff(EnvDTE.Project dteProject)
    {

    //Some hard code to get us going...                        

    Microsoft.Build.BuildEngine.Engine.GlobalEngine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727";

                     

    Microsoft.Build.BuildEngine.Project msBuildProject =

        new Microsoft.Build.BuildEngine.Project();

        

    msBuildProject.Load(dteProject.FullName);

     

    //works great..

    string data = msBuildProject.GetEvaluatedProperty("Something");

                     

    //also works great..

    msBuildProject.SetProperty("Something", "SomeValue");

     

    //and kaboom...

    msBuildProject.Save(dteProject.FullName);

    }

    -- TIA for any help.

All Replies

  • Tuesday, May 02, 2006 5:20 PM
     
     Answered

    Hello Roy

    I am guessing that you are manipulating existing project types using the automation model. In this case the MsBuild API is not available to you when working with the automation model. Trying to load the project in a separate msbuild project object in order to manipulate it is not recommended. Whenever you save the project file outside VS you will get prompted to reload the modified project file. That behaviour can not be changed.

    If you are manipulating C#/VB and J# projects you might find what you need in the VSProject Object model which is a language specific object that you can acces through the Project.Object Property.

    You can find reference documentation on MSDN for the core project automation model using this link:

    http://msdn2.microsoft.com/en-US/library/vslangproj(VS.80).aspx

    Thanks,

    Ole 

  • Monday, July 30, 2012 9:29 AM
     
      Has Code
    I've a problem which is when compiling the solution with VS, every thing is OK. But when compiling with MSBuild, this line of code returns NULL value:
    static DTE Dte;
    Dte = serviceProvider.GetService(typeof(SDTE)) as DTE;

    How can I solve this?

    please, contact me at: drhamada103@hotmail.com

    thanks in advace.


    • Edited by DrMAF Monday, July 30, 2012 9:29 AM
    •