Пример #1
0
        // =========================================================================================
        // Methods
        // =========================================================================================

        /// <summary>
        /// Entry point for all property validation in  projects.
        /// </summary>
        /// <param name="propertyName">Name of the property being validated. (The name in the project file, not the localized name.)</param>
        /// <param name="value">Property value to be validated.</param>
        public static void ValidateProperty(string propertyName, string value)
        {
            XHelperMethods.VerifyNonNullArgument(propertyName, "propertyName");
            XHelperMethods.VerifyNonNullArgument(value, "value");

            switch (propertyName)
            {
            case XProjectFileConstants.Cultures:
                ValidateCultures(propertyName, value);
                break;

            case XProjectFileConstants.OutputName:
                ValidateFilename(propertyName, value);
                break;

            case XProjectFileConstants.IntermediateOutputPath:
            case XProjectFileConstants.OutputPath:
                ValidatePath(propertyName, value);
                break;

            case XProjectFileConstants.IncludeSearchPaths:
                ValidatePath(propertyName, value);
                break;

            case XProjectFileConstants.ReferencePaths:
                ValidatePath(propertyName, value);
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Normalizes a text-field property value by trimming whitespace.
        /// Subclasses may override to do additional normalization.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">Property value entered by the user.</param>
        /// <returns>Normalized property value.</returns>
        public virtual string Normalize(string propertyName, string value)
        {
            XHelperMethods.VerifyStringArgument(propertyName, "propertyName");
            XHelperMethods.VerifyNonNullArgument(value, "value");

            return(value.Trim());
        }
Пример #3
0
        /// <summary>
        /// Instructs the property page to process the keystroke described in <paramref name="pMsg"/>.
        /// </summary>
        /// <param name="msg">Describes the keystroke to process.</param>
        /// <returns>
        /// <list type="table">
        /// <item><term>S_OK</term><description>The property page handles the accelerator.</description></item>
        /// <item><term>S_FALSE</term><description>The property page handles accelerators, but this one was not useful to it.</description></item>
        /// <item><term>E_NOTIMPL</term><description>The proeprty page does not handle accelerators.</description></item>
        /// </list>
        /// </returns>
        int IPropertyPage.TranslateAccelerator(MSG[] msg)
        {
            XHelperMethods.VerifyNonNullArgument(msg, "msg");

            // Always return S_FALSE otherwise we hijack all of the accelerators even for the menus
            return(VSConstants.S_FALSE);
        }
Пример #4
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="XPackageSettings"/> class.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param>
        public XPackageSettings(IServiceProvider serviceProvider)
        {
            XHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider");

            if (serviceProvider != null)
            {
                // get the Visual Studio registry root
                ILocalRegistry3 localRegistry = XHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider);
                ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot));
            }
        }
Пример #5
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Creates a new project property object.
        /// </summary>
        /// <param name="project">Project that owns the property.</param>
        /// <param name="propertyName">Name of the property.</param>
        public ProjectProperty(XProjectNode project, string propertyName)
        {
            XHelperMethods.VerifyNonNullArgument(project, "project");
            XHelperMethods.VerifyNonNullArgument(propertyName, "propertyName");

            this.project      = project;
            this.propertyName = propertyName;

            this.perUser          = ProjectProperty.PerUserProperties.Contains(propertyName);
            this.perConfig        = !ProjectProperty.NonPerConfigProperties.Contains(propertyName);
            this.allowVariables   = ProjectProperty.AllowVariablesProperties.Contains(propertyName);
            this.list             = ProjectProperty.ListProperties.Contains(propertyName);
            this.endOfProjectFile = ProjectProperty.EndOfProjectFileProperties.Contains(propertyName);
        }
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="XSharpBuildMacros"/> class.
        /// </summary>
        /// <param name="project">The project from which to read the properties.</param>
        public XBuildMacroCollection(ProjectNode project)
        {
            XHelperMethods.VerifyNonNullArgument(project, "project");

            // get the global SolutionX properties
            XBuildMacroCollection.DefineSolutionProperties(project);
            foreach (string globalMacroName in globalMacroNames)
            {
                string property = null;
                project.BuildProject.GlobalProperties.TryGetValue(globalMacroName, out property);
                if (null == property)
                {
                    this.list.Add(globalMacroName, "*Undefined*");
                }
                else
                {
                    this.list.Add(globalMacroName, property);
                }
            }
            // we need to call GetTargetPath first so that TargetDir and TargetPath are resolved correctly
            ConfigCanonicalName configCanonicalName;

            if (!Utilities.TryGetActiveConfigurationAndPlatform(project.Site, project, out configCanonicalName))
            {
                throw new InvalidOperationException();
            }
            BuildResult res = project.Build(configCanonicalName, XProjectFileConstants.GetTargetPath);

            // get the ProjectX and TargetX variables
            foreach (string macroName in macroNames)
            {
                string value;
                if (res.ProjectInstance != null)
                {
                    value = res.ProjectInstance.GetPropertyValue(macroName);
                }
                else
                {
                    value = project.GetProjectProperty(macroName);
                }

                this.list.Add(macroName, value);
            }
        }
Пример #7
0
        /// <summary>
        /// The environment calls this to get the parameters to describe the property page.
        /// </summary>
        /// <param name="pageInfos">The parameters are returned in this one-sized array.</param>
        void IPropertyPage.GetPageInfo(PROPPAGEINFO[] pageInfos)
        {
            XHelperMethods.VerifyNonNullArgument(pageInfos, "pageInfos");

            if (this.PropertyPagePanel == null)
            {
                this.PropertyPagePanel = this.CreatePropertyPagePanel();
            }

            PROPPAGEINFO info = new PROPPAGEINFO();

            info.cb            = (uint)Marshal.SizeOf(typeof(PROPPAGEINFO));
            info.dwHelpContext = 0;
            info.pszDocString  = null;
            info.pszHelpFile   = null;
            info.pszTitle      = this.PageName;
            info.SIZE.cx       = this.PropertyPagePanel.Width;
            info.SIZE.cy       = this.PropertyPagePanel.Height;
            pageInfos[0]       = info;
            this.propPageInfo  = info;
        }
Пример #8
0
        /// <summary>
        /// Sets the value of the property.
        /// </summary>
        /// <param name="value">Property value to set.</param>
        /// <param name="configs">Optional list of configurations to set the property in;
        /// defaults to the project current configuration</param>
        /// <remarks>
        /// Before calling this method, the caller must ensure that the value is valid according to
        /// the <see cref="PropertyValidator"/> class, and that the project file is writable.
        /// In most cases the caller should also ensure that the new value is different from the
        /// existing value, to avoid dirtying the project file unnecessarily.
        /// </remarks>
        public void SetValue(string value, IList <XProjectConfig> configs)
        {
            XHelperMethods.VerifyNonNullArgument(value, "value");

            value = value.Trim();

            MSBuild.Project buildProject = this.project.BuildProject;
            if (this.PerUser)
            {
                if (this.project.UserBuildProject == null)
                {
                    this.project.CreateUserBuildProject();
                }

                buildProject = this.project.UserBuildProject;
            }

            value = this.Escape(value);

            if (this.PerConfig)
            {
                if (configs == null || configs.Count == 0)
                {
                    configs = new XProjectConfig[] { (XProjectConfig)this.project.CurrentConfig };
                }

                foreach (XProjectConfig config in configs)
                {
                    bool set = false;

                    // First see if there's an existing property group that matches our condition
                    foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups)
                    {
                        // if there is, set it within that group
                        if (String.Equals(propGroup.Condition, config.Condition, StringComparison.Ordinal))
                        {
                            propGroup.SetProperty(this.propertyName, value);
                            set = true;
                            break;
                        }
                    }

                    // If not, add a new property group for the condition and set the property within it
                    if (!set)
                    {
                        ProjectPropertyGroupElement newPropGroup = buildProject.Xml.AddPropertyGroup();
                        newPropGroup.Condition = config.Condition;
                        newPropGroup.SetProperty(this.propertyName, value);
                        set = true;
                    }

                    buildProject.ReevaluateIfNecessary();
                }
            }
            else
            {
                if (this.EndOfProjectFile)
                {
                    List <ProjectPropertyGroupElement> propertyGroupsToDelete = new List <ProjectPropertyGroupElement>();
                    var groups = new List <ProjectPropertyGroupElement>();
                    // First see if there's an existing property group with our property
                    foreach (ProjectPropertyGroupElement propGroup in buildProject.Xml.PropertyGroups)
                    {
                        List <ProjectPropertyElement> propertiesToDelete = new List <ProjectPropertyElement>();
                        if (!String.IsNullOrEmpty(propGroup.Condition))
                        {
                            continue;
                        }
                        groups.Add(propGroup);
                        foreach (ProjectPropertyElement property in propGroup.Properties)
                        {
                            // if there is, remove it so the new value is at the end of the file
                            if (String.IsNullOrEmpty(property.Condition) && String.Equals(property.Name, this.propertyName, StringComparison.OrdinalIgnoreCase))
                            {
                                propertiesToDelete.Add(property);
                            }
                        }

                        foreach (ProjectPropertyElement property in propertiesToDelete)
                        {
                            propGroup.RemoveChild(property);
                        }
                        if (propGroup.Count == 0)
                        {
                            propertyGroupsToDelete.Add(propGroup);
                            groups.Remove(propGroup);
                        }
                    }

                    foreach (ProjectPropertyGroupElement propGroup in propertyGroupsToDelete)
                    {
                        buildProject.Xml.RemoveChild(propGroup);
                    }
                    ProjectPropertyGroupElement newPropGroup;
                    if (groups.Count > 1)
                    {
                        newPropGroup = groups[groups.Count - 1];
                    }
                    else
                    {
                        newPropGroup = buildProject.Xml.CreatePropertyGroupElement();
                        buildProject.Xml.AppendChild(newPropGroup);
                    }

                    newPropGroup.SetProperty(this.propertyName, value);
                }
                else
                {
                    buildProject.SetProperty(this.propertyName, value);
                }
            }

            this.project.InvalidatePropertyCache();
            this.project.SetProjectFileDirty(true);
        }