コード例 #1
0
        public void AddUpdateProperty(string propertyName, string newPropertyValue)
        {
            ProjectProperty prop = LoadedProj.GetProperty(propertyName);

            UtilLogger.LogInfo(MessageImportance.Low, "Processing Project '{0}'", this.ProjectFilePath);
            if (prop == null)
            {
                UtilLogger.LogInfo(MessageImportance.Low, "'{0}' property not found. Adding/setting it's value to '{1}'", propertyName, newPropertyValue);
                LoadedProj.SetProperty(propertyName, newPropertyValue);
                LoadedProj.Save(this.ProjectFilePath);
            }
            else
            {
                string currentValue = prop.EvaluatedValue;
                if (string.IsNullOrWhiteSpace(currentValue))
                {
                    UtilLogger.LogInfo(MessageImportance.Low, "Setting '{0}' value to '{1}'", propertyName, newPropertyValue);
                    LoadedProj.SetProperty(propertyName, newPropertyValue);
                    LoadedProj.Save(this.ProjectFilePath);
                }
                else
                {
                    UtilLogger.LogInfo(MessageImportance.Low, "Current value of '{0}' is '{1}'", propertyName, newPropertyValue);
                    if (!currentValue.Equals(newPropertyValue, StringComparison.OrdinalIgnoreCase))
                    {
                        UtilLogger.LogInfo(MessageImportance.Low, "Setting '{0}' value to '{1}'", propertyName, newPropertyValue);
                        LoadedProj.SetProperty(propertyName, newPropertyValue);
                        LoadedProj.Save(this.ProjectFilePath);
                    }
                }
            }
        }
コード例 #2
0
        public List <string> GetProjectReference()
        {
            List <string>             projRefs = new List <string>();
            ICollection <ProjectItem> pRefs    = LoadedProj.GetItemsIgnoringCondition(ITEMGROUP_PROJREF);

            if (pRefs.Any <ProjectItem>())
            {
                projRefs = pRefs.Select <ProjectItem, string>((item) => item.EvaluatedInclude).ToList <string>();
            }

            return(projRefs);
        }
コード例 #3
0
        public Dictionary <string, string> GetNugetPkgRefsAndVersionInfo(bool skipVersionInfo = false)
        {
            Dictionary <string, string>            pkgRefVer = null;
            List <Tuple <string, string, string> > pkgRefTup = new List <Tuple <string, string, string> >();
            ICollection <ProjectItem> pkgRefItems            = LoadedProj.GetItemsIgnoringCondition(ITEMGROUP_PKGREF);
            //ICollection<ProjectItem> pkgRefItems = LoadedProj.GetItemsByEvaluatedInclude(ITEMGROUP_PKGREF);
            //ICollection<ProjectItem> allItems = LoadedProj.ItemsIgnoringCondition;
            //ICollection<ProjectItem> pkgRefItems = allItems.Where<ProjectItem>((item) => item.ItemType.Equals(ITEMGROUP_PKGREF)).ToList<ProjectItem>();

            string piPkgRef     = string.Empty;
            string pkgRefVerStr = string.Empty;

            if (pkgRefItems.Any <ProjectItem>())
            {
                pkgRefVer = new Dictionary <string, string>();
                foreach (ProjectItem pi in pkgRefItems)
                {
                    piPkgRef = pi.EvaluatedInclude;

                    if (!pkgRefVer.ContainsKey(piPkgRef))
                    {
                        if (skipVersionInfo == false)
                        {
                            ICollection <ProjectMetadata> mdCol = pi.Metadata;
                            foreach (ProjectMetadata pimd in mdCol)
                            {
                                if (pimd.Name.Equals("Version", StringComparison.OrdinalIgnoreCase))
                                {
                                    string verStr = pimd.EvaluatedValue;
                                    if (!string.IsNullOrWhiteSpace(verStr))
                                    {
                                        NuGetVersion ver = GetMinimumNuGetVersion(verStr);
                                        if (ver != null)
                                        {
                                            pkgRefVerStr = ver.ToString();
                                            pkgRefVer.Add(piPkgRef, pkgRefVerStr);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            pkgRefVer.Add(piPkgRef, pkgRefVerStr);
                        }
                    }
                }
            }

            UtilLogger.LogInfo(MessageImportance.Low, pkgRefVer, "Retrieved PackageReferences and it's version");
            return(pkgRefVer);
        }
コード例 #4
0
        public string GetPropertyValue(string propertyName)
        {
            var propValue = LoadedProj.GetPropertyValue(propertyName);

            UtilLogger.LogInfo(MessageImportance.Low, "'{0}' - '{1}'", propertyName, propValue);

            if (propValue == null)
            {
                return(string.Empty);
            }
            else
            {
                return(propValue);
            }
        }
コード例 #5
0
        public string GetPropertyName(string propertyName)
        {
            ProjectProperty prop = LoadedProj.GetProperty(propertyName);

            UtilLogger.LogInfo(MessageImportance.Low, "Retrieved Property - '{0}'", prop?.Name);

            if (prop == null)
            {
                return(string.Empty);
            }
            else
            {
                return(prop.Name);
            }
        }