locked
Microsoft.Build.Evaluation.Project setting properties RRS feed

  • Question

  • Hi

    To set properties in the msbuild project file I used to use the obsolete Microsoft.Build.BuildEngine.Project class and call the SetProperty method. It contained three string parameters the last one being a condition to be able to write to the correct PropertyGroup condition in the project file. (.synproj in my case not .csproj) The Microsoft.Build.Evaluation.Project.SetProperty method only has two parameter, one for the property and one for the value.  It writes to the correct configuration for items that exist in the project file but not for any new items added by the property pages, they are all written into the general PropertyGroup in the project file.   How do I add new items to a conditional PropertyGroup like debug or release?

    Mark Cooper


    Synergex
    Friday, April 30, 2010 3:37 PM

Answers

  • The Microsoft.Build.BuildEngine.Project class that contains the SetProperty method is marked as obsolete in the MSDN.  That was the method I was using to set it. 

    Mark

     


    Synergex
    • Marked as answer by Synergex Monday, May 3, 2010 4:15 PM
    Monday, May 3, 2010 1:58 PM

All replies

  • Hi Synergex,

    Thanks for your post.

    Why don't you use Project.SetProperty Method in Microsoft.Build.BuildEngine Namespace, but not in Microsoft.Build.Evaluation Namespace? One member of SetProperty method in Microsoft.Build.BuildEngine Namespace contains three parameters including Condition parameter.

    If you want to add new items to a conditional PropertyGroup like debug or release, see following code:

    Project.SetProperty(“Optimize”, “true”, 
    "$(Configuration)|$(Platform)' == 'Debug|AnyCPU'”);

     For more information, please see MSDN Blog: How the IDE Writes Properties.

    If I misunderstood you, or you have any comments, please feel free to let me know.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 3, 2010 6:12 AM
  • The Microsoft.Build.BuildEngine.Project class that contains the SetProperty method is marked as obsolete in the MSDN.  That was the method I was using to set it. 

    Mark

     


    Synergex
    • Marked as answer by Synergex Monday, May 3, 2010 4:15 PM
    Monday, May 3, 2010 1:58 PM
  • I was able to use the MPF class Microsoft.VisualStudio.Project.ProjectConfig methods GetConfigurationProperty and SetConfigurationProperty.  Once I got the configuration I wanted to work with in the property page I could use the ProjectConfig class to get and set the correct configuration properties.

    Mark


    Synergex
    Monday, May 3, 2010 4:20 PM
  • Hi,

    I used to add import targets elements to loaded projects using:

    Microsoft.Build.BuildEngine.Project object,

    Microsoft.Build.BuildEngine.Project.AddNewImport method.

     

    Now, as this object is marked obsolete, I am forced to use:

    Microsoft.Build.Evaluation.Project object, which does not include any method of the sort.

    Am I missing something? where did all the API go? Have you stopped supporting it entirely?

     

    Adding an item to 'Imports' member requires the ability to init a ResolvedImport instance and setting it's properties which are read-only. So that's out of the question...

     

    Can you please help me achieve the same result?

     

    Thanks,

    Dror Shahak

    Monday, May 17, 2010 2:59 PM
  • Hi,

     

    You can try

    buildProject.Xml.AddImport("Project=\"$(MSBuildExtensionsPath32)"+@"\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets");

    where buildProject is of type -> Microsoft.Build.Evaluation.Project.

     

    Hope this helps.

     

    Thanks

    Inder

    • Proposed as answer by Inder Gujral Thursday, October 21, 2010 10:39 AM
    Thursday, October 21, 2010 10:39 AM