none
How to persist project configuration specific properties

    Question

  • Hi,

    we plan to create an add-in (using C#) for VS2005 that adds some functionality to the C++ project type. How can I persist parameters/settings that are specific for a configuration of the project? Am I restricted to use Project.Globals or is there a way to store private properties in the project file under the corresponding configuration?

    Udo Eberhardt
    Wednesday, September 14, 2005 7:06 PM

Answers

  • The best way of doing this is to use Project.Globals, there is no way to directly modify the XML of the project file in a way that is safe.

    Craig
    Monday, October 31, 2005 7:18 PM

All replies

  • The best way of doing this is to use Project.Globals, there is no way to directly modify the XML of the project file in a way that is safe.

    Craig
    Monday, October 31, 2005 7:18 PM
  • Would it be a bad idea to add a unique Id element to all newly created project items so that I can reference data associated with it from an external storage place of my choice?

            /// <summary>
            /// Adds a new attribute to the project item.
            /// </summary>
            /// <param name="project">The project that contains the project item.</param>
            /// <param name="fullPath">The full path of the project item.</param>
            /// <param name="key">The key for the attribute property.</param>
            /// <param name="value">The value for the property.</param>
            /// <returns>The property saved as a string.</returns>
            /// <remarks>Returns the existing value if it already exists.</remarks>
            public static String Add(Project project, String fullPath, String key, String value)
            {
                var hierarchy = HierarchyHelper.GetHierarchy(Globals.ServiceProvider, project);
                var buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;
                var result = String.Empty;
                if (buildPropertyStorage != null)
                {
                    uint itemId;
                    
                    hierarchy.ParseCanonicalName(fullPath, out itemId);
                    buildPropertyStorage.GetItemAttribute(itemId, key, out result);
    
                    // This ID is used for storage within the project item.
                    if (String.IsNullOrEmpty(result))
                    {
                        result = value;
                        buildPropertyStorage.SetItemAttribute(itemId, key, result);
                        project.Save();
                    }
                }
    
                return result;
            }




    • Edited by jwize Saturday, June 23, 2012 9:50 AM
    Saturday, June 23, 2012 9:49 AM