locked
Custom Property in <PropertyGroup> RRS feed

  • Question

  • Hi,

    I have been working on a VS Extension for adding new Item Template. When user will select new item using that template, I need to add a custom property (say MYCUSTOMPROPERTY) inside <PropertyGroup> as shown below:

     

    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProductVersion>9.0.30729</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{985592DE-2F37-4448-A5D1-13173A088AA1}</ProjectGuid>
     .
     .
     .
     <MYCUSTOMPROPERTY>MyCustomValue</MYCUSTOMPROPERTY>
     </PropertyGroup>
    </Project>

    Since I have not developing project template, I can't modify the project template. Is there any way to add custom property inside <PropertyGroup>? I have tried the Project.ConfigurationManager.ActiveConfiguration.Properties but there's no way to add new property but to modify existing property.

     


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    Monday, July 26, 2010 12:01 PM

Answers

  • Hello,

    This is not achievable in automation extensibility. But we could using the API the SDK provides us. I have written sample code for you to show how to do this.

                IVsSolution sln = GetService(typeof(SVsSolution)) as IVsSolution;

                DTE dte = GetService(typeof(SDTE)) as DTE;

                IVsHierarchy hiearachy = null;

                sln.GetProjectOfUniqueName(dte.Solution.Projects.Item(1).FullName, out hiearachy);

                IVsBuildPropertyStorage buildPropStorage = (IVsBuildPropertyStorage)hiearachy;

                ErrorHandler.ThrowOnFailure(buildPropStorage.SetPropertyValue("MYCUSTOMPROPERTY",String.Empty,(uint)_PersistStorageType.PST_PROJECT_FILE, "MyCustomValue"));

    PS: You could use GetService to get the service if you are using Add-in.

    If you have anything unclear, feel free to let me know.

    Thanks

    Chao

    Tuesday, July 27, 2010 8:10 AM

All replies

  • Hello,

    This is not achievable in automation extensibility. But we could using the API the SDK provides us. I have written sample code for you to show how to do this.

                IVsSolution sln = GetService(typeof(SVsSolution)) as IVsSolution;

                DTE dte = GetService(typeof(SDTE)) as DTE;

                IVsHierarchy hiearachy = null;

                sln.GetProjectOfUniqueName(dte.Solution.Projects.Item(1).FullName, out hiearachy);

                IVsBuildPropertyStorage buildPropStorage = (IVsBuildPropertyStorage)hiearachy;

                ErrorHandler.ThrowOnFailure(buildPropStorage.SetPropertyValue("MYCUSTOMPROPERTY",String.Empty,(uint)_PersistStorageType.PST_PROJECT_FILE, "MyCustomValue"));

    PS: You could use GetService to get the service if you are using Add-in.

    If you have anything unclear, feel free to let me know.

    Thanks

    Chao

    Tuesday, July 27, 2010 8:10 AM
  • Chao,

     

    Thanks for reply. I'll give a try and come back to you.

     

     


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    Wednesday, July 28, 2010 4:09 AM
  • Hi, Sohel Rana

    This code works on my side. I will close this thread, and if this does not help, unmark it and let me know what is the problem.

    Thanks

    Chao


    Please unmark it if it does not help, and mark it if it helps.
    Monday, August 2, 2010 2:35 AM