public void SetProperty(string propertyName, _PersistStorageType storageType, string propertyValue, string condition, bool treatPropertyValueAsLiteral)
 {
     if (ProjectManager != null)
     {
         ProjectManager.SetProjectProperty(propertyName, storageType, propertyValue ?? string.Empty, condition, treatPropertyValueAsLiteral);
     }
 }
Example #2
0
        // relative to active configuration.
        public virtual string GetConfigProperty(string propertyName, _PersistStorageType storageType)
        {
            if (this.ProjectManager != null)
            {
                string unifiedResult  = null;
                bool   cacheNeedReset = true;

                for (int i = 0; i < this.projectConfigs.Length; i++)
                {
                    ProjectConfig config   = projectConfigs[i];
                    string        property = config.GetConfigurationProperty(propertyName, storageType, cacheNeedReset);
                    cacheNeedReset = false;

                    if (property != null)
                    {
                        string text = property.Trim();

                        if (i == 0)
                        {
                            unifiedResult = text;
                        }
                        else if (unifiedResult != text)
                        {
                            return("");                            // tristate value is blank then
                        }
                    }
                }

                return(unifiedResult);
            }

            return(String.Empty);
        }
        public string GetConfigProperty(string propertyName, _PersistStorageType storageType)
        {
            string unifiedResult = string.Empty;

            if (ProjectManager != null)
            {
                bool cacheNeedReset = true;

                for (int i = 0; i < _projectConfigs.Length; i++)
                {
                    ProjectConfig config   = _projectConfigs[i];
                    string        property = config.GetConfigurationProperty(propertyName, storageType, cacheNeedReset);

                    cacheNeedReset = false;

                    if (property != null)
                    {
                        string text = property.Trim();

                        if (i == 0)
                        {
                            unifiedResult = text;
                        }
                        else if (unifiedResult != text)
                        {
                            unifiedResult = string.Empty;
                            break;
                        }
                    }
                }
            }

            return(unifiedResult);
        }
 public void SetProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
 {
     if (ProjectManager != null)
     {
         ProjectManager.SetProjectProperty(propertyName, storageType, propertyValue ?? string.Empty);
     }
 }
 public ProjectBuildProperty(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type, _PersistStorageType typeDefault, string valDefault)
 {
     m_propName        = propName;
     m_storage         = storage;
     m_cfg             = cfg;
     m_type            = type;
     m_fPropertyLoaded = false;
     m_valDefault      = valDefault;
     m_typeDefault     = typeDefault;
 }
Example #6
0
        /// <summary>
        /// If flavored, and if the flavor config can be dirty, ask it if it is dirty
        /// </summary>
        /// <param name="storageType">Project file or user file</param>
        /// <returns>0 = not dirty</returns>
        internal int IsFlavorDirty(_PersistStorageType storageType)
        {
            int isDirty = 0;

            if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
            {
                ((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty);
            }
            return(isDirty);
        }
Example #7
0
        /// <summary>
        /// If flavored, and if the flavor config can be dirty, ask it if it is dirty
        /// </summary>
        /// <param name="storageType">Project file or user file</param>
        /// <returns>0 = not dirty</returns>
        internal int IsFlavorDirty(_PersistStorageType storageType)
        {
            int isDirty = 0;

            if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
            {
                ErrorHandler.ThrowOnFailure(((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty));
            }
            return(isDirty);
        }
Example #8
0
        public virtual string GetConfigurationProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectPropertyInstance property = GetMsBuildProperty(propertyName, storageType, resetCache);
            if (property == null)
            {
                return(null);
            }

            return(property.EvaluatedValue);
        }
Example #9
0
        /// <summary>
        /// If flavored, ask the flavor if it wants to provide an XML fragment
        /// </summary>
        /// <param name="flavor">Guid of the flavor</param>
        /// <param name="storageType">Project file or user file</param>
        /// <param name="fragment">Fragment that the flavor wants to save</param>
        /// <returns>HRESULT</returns>
        internal int GetXmlFragment(Guid flavor, _PersistStorageType storageType, out string fragment)
        {
            fragment = null;
            int hr = VSConstants.S_OK;

            if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
            {
                Guid flavorGuid = flavor;
                hr = ((IPersistXMLFragment)this.flavoredCfg).Save(ref flavorGuid, (uint)storageType, out fragment, 1);
            }
            return(hr);
        }
Example #10
0
        public virtual object GetTypedProperty(string name, Type type, _PersistStorageType storageType)
        {
            string value = GetProperty(name, storageType);

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            TypeConverter tc = TypeDescriptor.GetConverter(type);

            return(tc.ConvertFromInvariantString(value));
        }
        public string GetProperty(string propertyName, _PersistStorageType storageType)
        {
            if (ProjectManager != null)
            {
                string property = ProjectManager.GetProjectProperty(propertyName, storageType, true);
                if (property != null)
                {
                    return(property);
                }
            }

            return(string.Empty);
        }
        public int GetConfigPropertyInt32(string propertyName, _PersistStorageType storageType)
        {
            string value = GetConfigProperty(propertyName, storageType);

            int converted;

            if (string.IsNullOrEmpty(value) || !int.TryParse(value, out converted))
            {
                return(JavaProjectFileConstants.UnspecifiedValue);
            }

            return(converted);
        }
        public bool GetConfigPropertyBoolean(string propertyName, _PersistStorageType storageType)
        {
            string value = GetConfigProperty(propertyName, storageType);

            bool converted;

            if (string.IsNullOrEmpty(value) || !bool.TryParse(value, out converted))
            {
                return(false);
            }

            return(converted);
        }
Example #14
0
        public virtual void SetConfigurationProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
        {
            if (!this._project.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            string condition = ProjectManager.ConfigProvider.GetConfigurationPlatformCondition(this.ConfigName, this.Platform);

            ProjectManager.SetPropertyUnderCondition(propertyName, storageType, condition, propertyValue);
            Invalidate();

            return;
        }
Example #15
0
        public virtual string GetProperty(string propertyName, _PersistStorageType storageType)
        {
            if (this.ProjectManager != null)
            {
                string property;
                bool   found = this.ProjectManager.BuildProject.GlobalProperties.TryGetValue(propertyName, out property);

                if (found)
                {
                    return(property);
                }
            }

            return(String.Empty);
        }
        public void SetConfigProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
        {
            if (propertyValue == null)
            {
                propertyValue = string.Empty;
            }

            if (ProjectManager != null)
            {
                for (int i = 0, n = _projectConfigs.Length; i < n; i++)
                {
                    ProjectConfig config = _projectConfigs[i];
                    config.SetConfigurationProperty(propertyName, storageType, propertyValue);
                }

                ProjectManager.SetProjectFileDirty(true);
            }
        }
Example #17
0
        /// <summary>
        /// Sets the value of a configuration dependent property.
        /// If the attribute does not exist it is created.
        /// If value is null it will be set to an empty string.
        /// </summary>
        /// <param name="name">property name.</param>
        /// <param name="value">value of property</param>
        public virtual void SetConfigProperty(string name, _PersistStorageType storageType, string value)
        {
            CciTracing.TraceCall();
            if (value == null)
            {
                value = String.Empty;
            }

            if (this.ProjectManager != null)
            {
                for (int i = 0, n = this.projectConfigs.Length; i < n; i++)
                {
                    ProjectConfig config = projectConfigs[i];

                    config.SetConfigurationProperty(name, storageType, value);
                }

                this.ProjectManager.SetProjectFileDirty(true);
            }
        }
        private string GetPropertyValueHelper(_PersistStorageType type)
        {
            string val = null;

            if (m_storage == null)
            {
                return(null);
            }

            try
            {
                m_storage.GetPropertyValue(m_propName, this.GetConfigName(false), (uint)type, out val);
            }
            catch (COMException e)
            {
                if (e.ErrorCode != Utility.COM_HResults.ERR_XML_ATTRIBUTE_NOT_FOUND)
                {
                    throw;
                }
            }

            return(val);
        }
Example #19
0
        protected virtual MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            ProjectInstance projectInstance = this.currentConfig;
            if (resetCache || this.currentConfig == null || storageType == _PersistStorageType.PST_USER_FILE)
            {
                // Get properties from project file and cache it
                this.SetCurrentConfiguration();
                this.currentConfig = this.buildProject.CreateProjectInstance();
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                    projectInstance = this.currentConfig;
                else if (UserBuildProject != null)
                    projectInstance = UserBuildProject.CreateProjectInstance();
            }

            if (projectInstance == null)
            {
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FailedToRetrieveProperties, CultureInfo.CurrentUICulture), propertyName));

                return null;
            }

            // return property asked for
            return GetMsBuildProperty(projectInstance, propertyName);
        }
Example #20
0
        /// <summary>
        /// Set value of project property
        /// </summary>
        /// <param name="propertyName">Name of property</param>
        /// <param name="propertyValue">Value of property</param>
        public virtual void SetProjectProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
        {
            if (propertyName == null)
                throw new ArgumentNullException("propertyName", "Cannot set a null project property");

            string oldValue = null;
            ProjectPropertyInstance oldProp = GetMsBuildProperty(propertyName, storageType, true);
            if (oldProp != null)
                oldValue = oldProp.EvaluatedValue;

            if (propertyValue == null)
            {
                // if property already null, do nothing
                if (oldValue == null)
                    return;

                // otherwise, set it to empty
                propertyValue = String.Empty;
            }

            // Only do the work if this is different to what we had before
            if (!String.Equals(oldValue, propertyValue, StringComparison.Ordinal))
            {
                // Check out the project file.
                if (storageType == _PersistStorageType.PST_PROJECT_FILE && !this.ProjectManager.QueryEditProjectFile(false))
                {
                    throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                }

                MSBuild.Project project = (storageType == _PersistStorageType.PST_PROJECT_FILE) ? this.BuildProject : this.GetOrCreateUserBuildProject();
                project.SetProperty(propertyName, propertyValue);
                OnProjectPropertyChanged(new ProjectPropertyChangedArgs(propertyName, oldValue, propertyValue));

                // property cache will need to be updated
                this.currentConfig = null;
                this.SetProjectFileDirty(true);
            }
        }
Example #21
0
        /// <summary>
        /// Return the value of a project property
        /// </summary>
        /// <param name="propertyName">Name of the property to get</param>
        /// <param name="resetCache">True to avoid using the cache</param>
        /// <returns>null if property does not exist, otherwise value of the property</returns>
        public virtual string GetProjectProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectPropertyInstance property = GetMsBuildProperty(propertyName, storageType, resetCache);
            if (property == null)
                return null;

            return property.EvaluatedValue;
        }
        public virtual string GetProperty(string propertyName, _PersistStorageType storageType)
        {
            if(this.ProjectManager != null)
            {
                string property;
                bool found = this.ProjectManager.BuildProject.GlobalProperties.TryGetValue(propertyName, out property);

                if(found)
                {
                    return property;
                }
            }

            return String.Empty;
        }
Example #23
0
 public void SetConfigProperty(string propertyName, _PersistStorageType storageType, bool propertyValue)
 {
     SetConfigProperty(propertyName, storageType, propertyValue.ToString());
 }
Example #24
0
        public int GetConfigPropertyInt32(string propertyName, _PersistStorageType storageType)
        {
            string value = GetConfigProperty(propertyName, storageType);

            int converted;
            if (string.IsNullOrEmpty(value) || !int.TryParse(value, out converted))
                return DartProjectFileConstants.UnspecifiedValue;

            return converted;
        }
        /// <summary>
        /// Sets the value of a configuration dependent property.
        /// If the attribute does not exist it is created.  
        /// If value is null it will be set to an empty string.
        /// </summary>
        /// <param name="name">property name.</param>
        /// <param name="value">value of property</param>
        public virtual void SetConfigProperty(string name, _PersistStorageType storageType, string value)
        {
            CciTracing.TraceCall();
            if(value == null)
            {
                value = String.Empty;
            }

            if(this.ProjectManager != null)
            {
                for(int i = 0, n = this.projectConfigs.Length; i < n; i++)
                {
                    ProjectConfig config = projectConfigs[i];

                    config.SetConfigurationProperty(name, storageType, value);
                }

                this.ProjectManager.SetProjectFileDirty(true);
            }
        }
        // relative to active configuration.
        public virtual string GetConfigProperty(string propertyName, _PersistStorageType storageType)
        {
            if(this.ProjectManager != null)
            {
                string unifiedResult = null;
                bool cacheNeedReset = true;

                for(int i = 0; i < this.projectConfigs.Length; i++)
                {
                    ProjectConfig config = projectConfigs[i];
                    string property = config.GetConfigurationProperty(propertyName, storageType, cacheNeedReset);
                    cacheNeedReset = false;

                    if(property != null)
                    {
                        string text = property.Trim();

                        if(i == 0)
                            unifiedResult = text;
                        else if(unifiedResult != text)
                            return ""; // tristate value is blank then
                    }
                }

                return unifiedResult;
            }

            return String.Empty;
        }
        private void GetEmulatorConfigHelper(ref bool emulatorValue, string propName, _PersistStorageType storage)
        {
            string val = null;

            GetEmulatorConfigHelper(ref val, propName, storage);

            if (!string.IsNullOrEmpty(val))
            {
                bool.TryParse(val, out emulatorValue);
            }
        }
        private void GetEmulatorConfigHelper(ref string emulatorValue, string propName, _PersistStorageType storage)
        {
            string val;

            this.m_IVsBuildPropertyStorage.GetPropertyValue(propName, this.GetName(false), (uint)storage, out val);

            if (!string.IsNullOrEmpty(val))
            {
                emulatorValue = val;
            }
        }
 public ProjectBuildPropertyBool(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type) : base(propName, storage, cfg, type)
 {
 }
 public ProjectBuildProperty(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type)
     : this(propName, storage, cfg, type, PersistStorageTypeNone, string.Empty)
 {
 }
 public AllConfigurationsProperties(IProject project, bool userData)
 {
     this.project     = project;
     this.userData    = userData;
     this.storageType = userData ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE;
 }
        public virtual void SetConfigurationProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
        {
            if(!this._project.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            string condition = ProjectManager.ConfigProvider.GetConfigurationPlatformCondition(this.ConfigName, this.Platform);
            ProjectManager.SetPropertyUnderCondition(propertyName, storageType, condition, propertyValue);
            Invalidate();

            return;
        }
Example #33
0
 /// <summary>
 /// If flavored, and if the flavor config can be dirty, ask it if it is dirty
 /// </summary>
 /// <param name="storageType">Project file or user file</param>
 /// <returns>0 = not dirty</returns>
 /*internal, but public for FSharp.Project.dll*/ public int IsFlavorDirty(_PersistStorageType storageType)
 {
     int isDirty = 0;
     if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
     {
         ((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty);
     }
     return isDirty;
 }
Example #34
0
 public SpecificPlatformProperties(IProject project, string platform, bool userData)
 {
     this.project     = project;
     this.platform    = platform;
     this.storageType = userData ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE;
 }
Example #35
0
        public bool GetConfigPropertyBoolean(string propertyName, _PersistStorageType storageType)
        {
            string value = GetConfigProperty(propertyName, storageType);

            bool converted;
            if (string.IsNullOrEmpty(value) || !bool.TryParse(value, out converted))
                return false;

            return converted;
        }
Example #36
0
        public void SetConfigProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
        {
            if (propertyValue == null)
            {
                propertyValue = string.Empty;
            }

            if (ProjectManager != null)
            {
                for (int i = 0, n = _projectConfigs.Length; i < n; i++)
                {
                    ProjectConfig config = _projectConfigs[i];
                    config.SetConfigurationProperty(propertyName, storageType, propertyValue);
                }

                ProjectManager.SetProjectFileDirty(true);
            }
        }
Example #37
0
        public string GetProperty(string propertyName, _PersistStorageType storageType)
        {
            if (ProjectManager != null)
            {
                string property = ProjectManager.GetProjectProperty(propertyName, storageType, true);
                if (property != null)
                    return property;
            }

            return string.Empty;
        }
Example #38
0
 public void SetProperty(string propertyName, _PersistStorageType storageType, string propertyValue, string condition, bool treatPropertyValueAsLiteral)
 {
     if (ProjectManager != null)
         ProjectManager.SetProjectProperty(propertyName, storageType, propertyValue ?? string.Empty, condition, treatPropertyValueAsLiteral);
 }
Example #39
0
 public void SetConfigProperty(string propertyName, _PersistStorageType storageType, int propertyValue)
 {
     SetConfigProperty(propertyName, storageType, propertyValue.ToString(CultureInfo.InvariantCulture));
 }
        protected virtual MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectInstance requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;
            if (resetCache || requestedConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this._project.SetConfiguration(this.ConfigName, this.Platform);
                this._project.BuildProject.ReevaluateIfNecessary();
                if (this._project.UserBuildProject != null)
                    this._project.UserBuildProject.ReevaluateIfNecessary();

                // Create a snapshot of the evaluated project in its current state
                this.currentConfig = this._project.BuildProject.CreateProjectInstance();
                if (this._project.UserBuildProject != null)
                    this.currentUserConfig = this._project.UserBuildProject.CreateProjectInstance();

                requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;

                // Restore configuration
                _project.SetCurrentConfiguration();
            }

            if (requestedConfig == null)
            {
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FailedToRetrieveProperties, CultureInfo.CurrentUICulture), propertyName));

                // user build projects aren't essential
                return null;
            }

            // return property asked for
            return requestedConfig.GetProperty(propertyName);
        }
Example #41
0
 public void SetProperty(string propertyName, _PersistStorageType storageType, string propertyValue)
 {
     if (ProjectManager != null)
         ProjectManager.SetProjectProperty(propertyName, storageType, propertyValue ?? string.Empty);
 }
        /// <summary>
        /// Tries to set a build property on the project.
        /// </summary>
        public static bool TrySetBuildProperty(this IVsHierarchy hierarchy, string name, string value, _PersistStorageType storageType = _PersistStorageType.PST_USER_FILE)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (hierarchy is IVsBuildPropertyStorage storage)
            {
                // Store the build property in the user file instead of the project
                // file, because we don't want to affect the real project file.
                storage.SetPropertyValue(name, "", (uint)storageType, value);
                return(true);
            }

            return(false);
        }
Example #43
0
 /// <summary>
 ///     If flavored, ask the flavor if it wants to provide an XML fragment
 /// </summary>
 /// <param name="flavor">Guid of the flavor</param>
 /// <param name="storageType">Project file or user file</param>
 /// <param name="fragment">Fragment that the flavor wants to save</param>
 /// <returns>HRESULT</returns>
 internal int GetXmlFragment(Guid flavor, _PersistStorageType storageType, out string fragment)
 {
     fragment = null;
     var hr = VSConstants.S_OK;
     if (flavoredCfg != null && flavoredCfg is IPersistXMLFragment)
     {
         var flavorGuid = flavor;
         hr = ((IPersistXMLFragment) flavoredCfg).Save(ref flavorGuid, (uint) storageType, out fragment, 1);
     }
     return hr;
 }
        /// <summary>
        /// Tries to get the specified build property from the project.
        /// </summary>
        public static bool TryGetBuildProperty(this IVsHierarchy hierarchy, string name, out string?value, _PersistStorageType storageType = _PersistStorageType.PST_USER_FILE)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            value = null;

            if (hierarchy is IVsBuildPropertyStorage storage)
            {
                return(storage.GetPropertyValue(name, "", (uint)storageType, out value) == VSConstants.S_OK);
            }

            return(false);
        }
Example #45
0
 /// <summary>
 /// Get value of Project property
 /// </summary>
 /// <param name="propertyName">Name of Property to retrieve</param>
 /// <returns>Evaluated value of property.</returns>
 public virtual string GetProjectProperty(string propertyName, _PersistStorageType storageType)
 {
     return this.GetProjectProperty(propertyName, storageType, true);
 }
        private void GetEmulatorConfigHelper(ref string emulatorValue, string propName, _PersistStorageType storage)
        {
            string val;

            this.m_IVsBuildPropertyStorage.GetPropertyValue(propName, this.GetName(false), (uint)storage, out val);

            if (!string.IsNullOrEmpty(val))
            {
                emulatorValue = val;
            }
        }
Example #47
0
        public virtual void SetPropertyUnderCondition(string propertyName, _PersistStorageType storageType, string condition, string propertyValue)
        {
            if (propertyName == null)
                throw new ArgumentNullException("propertyName");

            if (string.IsNullOrWhiteSpace(condition))
            {
                SetProjectProperty(propertyName, storageType, propertyValue);
                return;
            }

            string conditionTrimmed = condition.Trim();
            MSBuild.Project project = (storageType == _PersistStorageType.PST_PROJECT_FILE) ? BuildProject : GetOrCreateUserBuildProject();
            MSBuildConstruction.ProjectPropertyGroupElement destinationGroup = null;
            foreach (MSBuildConstruction.ProjectPropertyGroupElement group in project.Xml.PropertyGroups)
            {
                if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase))
                {
                    destinationGroup = group;
                    break;
                }
            }

            if (destinationGroup == null)
            {
                MSBuildConstruction.ProjectElement lastRelevantElement = null;
                foreach (MSBuildConstruction.ProjectPropertyGroupElement group in project.Xml.PropertyGroupsReversed)
                {
                    if (string.IsNullOrEmpty(group.Condition))
                        continue;

                    if (group.Condition.IndexOf("'$(Configuration)'", StringComparison.OrdinalIgnoreCase) >= 0
                        || group.Condition.IndexOf("'$(Platform)'", StringComparison.OrdinalIgnoreCase) >= 0
                        || group.Condition.IndexOf("'$(Configuration)|$(Platform)'", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        lastRelevantElement = group;
                        break;
                    }
                }

                if (lastRelevantElement == null)
                    lastRelevantElement = project.Xml.PropertyGroupsReversed.FirstOrDefault();

                destinationGroup = project.Xml.CreatePropertyGroupElement();
                project.Xml.InsertAfterChild(destinationGroup, lastRelevantElement);
                destinationGroup.Condition = condition;
            }

            foreach (MSBuildConstruction.ProjectPropertyElement property in destinationGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
            {
                if (String.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) && property.Condition.Length == 0)
                {
                    property.Value = propertyValue;
                    return;
                }
            }

            destinationGroup.AddProperty(propertyName, propertyValue);
        }
Example #48
0
 /// <summary>
 /// If flavored, and if the flavor config can be dirty, ask it if it is dirty
 /// </summary>
 /// <param name="storageType">Project file or user file</param>
 /// <returns>0 = not dirty</returns>
 internal int IsFlavorDirty(_PersistStorageType storageType) {
     int isDirty = 0;
     if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment) {
         ErrorHandler.ThrowOnFailure(((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty));
     }
     return isDirty;
 }
 public SpecificConfigurationProperties(IProject project, string configuration, bool userData)
 {
     this.project       = project;
     this.configuration = configuration;
     this.storageType   = userData ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE;
 }
Example #50
0
 /// <summary>
 /// If flavored, and if the flavor config can be dirty, ask it if it is dirty
 /// </summary>
 /// <param name="storageType">Project file or user file</param>
 /// <returns>0 = not dirty</returns>
 public int IsFlavorDirty(_PersistStorageType storageType)
 {
     int isDirty = 0;
     if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
     {
         ((IPersistXMLFragment)this.flavoredCfg).IsFragmentDirty((uint)storageType, out isDirty);
     }
     return isDirty;
 }
 public SpecificConfigurationAndPlatformProperties(IProject project, string configurationAndPlatform, bool userData)
 {
     this.project = project;
     this.configurationAndPlatform = configurationAndPlatform;
     this.storageType = userData ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE;
 }
        private void GetEmulatorConfigHelper(ref bool emulatorValue, string propName, _PersistStorageType storage)
        {
            string val = null;

            GetEmulatorConfigHelper(ref val, propName, storage);

            if (!string.IsNullOrEmpty(val))
            {
                bool.TryParse(val, out emulatorValue);
            }
        }
 public SpecificPlatformProperties(IProject project, string platform, bool userData)
 {
     this.project = project;
     this.platform = platform;
     this.storageType = userData ? _PersistStorageType.PST_USER_FILE : _PersistStorageType.PST_PROJECT_FILE;
 }
        public virtual object GetTypedProperty(string name, Type type, _PersistStorageType storageType)
        {
            string value = GetProperty(name, storageType);
            if(string.IsNullOrEmpty(value)) return null;

            TypeConverter tc = TypeDescriptor.GetConverter(type);
            return tc.ConvertFromInvariantString(value);
        }
        public static void SetProjectProperty(IVsSolution solution, Project project, string propertyName, string propertyValue, string configName, _PersistStorageType persistStorageType)
        {
            IVsHierarchy            hierarchy            = GetHierarchy(solution, project);
            IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;

            buildPropertyStorage.SetPropertyValue(propertyName, configName, (uint)persistStorageType, propertyValue);
        }
Example #56
0
        protected virtual MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectInstance requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;
            if (resetCache || requestedConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this._project.SetConfiguration(this.ConfigName, this.Platform);
                this._project.BuildProject.ReevaluateIfNecessary();
                if (this._project.UserBuildProject != null)
                {
                    this._project.UserBuildProject.ReevaluateIfNecessary();
                }

                // Create a snapshot of the evaluated project in its current state
                this.currentConfig = this._project.BuildProject.CreateProjectInstance();
                if (this._project.UserBuildProject != null)
                {
                    this.currentUserConfig = this._project.UserBuildProject.CreateProjectInstance();
                }

                requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;

                // Restore configuration
                _project.SetCurrentConfiguration();
            }

            if (requestedConfig == null)
            {
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FailedToRetrieveProperties, CultureInfo.CurrentUICulture), propertyName));
                }

                // user build projects aren't essential
                return(null);
            }

            // return property asked for
            return(requestedConfig.GetProperty(propertyName));
        }
Example #57
0
 /// <summary>
 /// If flavored, ask the flavor if it wants to provide an XML fragment
 /// </summary>
 /// <param name="flavor">Guid of the flavor</param>
 /// <param name="storageType">Project file or user file</param>
 /// <param name="fragment">Fragment that the flavor wants to save</param>
 /// <returns>HRESULT</returns>
 public int GetXmlFragment(Guid flavor, _PersistStorageType storageType, out string fragment)
 {
     fragment = null;
     int hr = VSConstants.S_OK;
     if (this.flavoredCfg != null && this.flavoredCfg is IPersistXMLFragment)
     {
         Guid flavorGuid = flavor;
         hr = ((IPersistXMLFragment)this.flavoredCfg).Save(ref flavorGuid, (uint)storageType, out fragment, 1);
     }
     return hr;
 }
        /// <summary>
        /// Tries to get the specified build property from the project.
        /// </summary>
        /// <returns>The <c>string</c> representation of the value or <c>null</c> if the property doesn't exist.</returns>
        public static async Task <string?> GetBuildPropertyAsync(this Project project, string name, _PersistStorageType storageType = _PersistStorageType.PST_USER_FILE)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsHierarchy?hierarchy = await project.ToHierarchyAsync();

            if (hierarchy != null && hierarchy.TryGetBuildProperty(name, out var value, storageType))
            {
                return(value);
            }

            return(null);
        }
 public ProjectBuildPropertyBool(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type) : base (propName, storage, cfg, type)
 {
 }
Example #60
0
        public string GetConfigProperty(string propertyName, _PersistStorageType storageType)
        {
            string unifiedResult = string.Empty;

            if (ProjectManager != null)
            {
                bool cacheNeedReset = true;

                for (int i = 0; i < _projectConfigs.Length; i++)
                {
                    ProjectConfig config = _projectConfigs[i];
                    string property = config.GetConfigurationProperty(propertyName, storageType, cacheNeedReset);

                    cacheNeedReset = false;

                    if (property != null)
                    {
                        string text = property.Trim();

                        if (i == 0)
                        {
                            unifiedResult = text;
                        }
                        else if (unifiedResult != text)
                        {
                            unifiedResult = string.Empty;
                            break;
                        }
                    }
                }
            }

            return unifiedResult;
        }