예제 #1
0
        public VSProjectItem(VSProject project, object internalProjectItem, VSProjectItem parentItem = null, bool isHidden = false)
        {
            FileInfo file;

            if (internalProjectItem is string)
            {
                var path = (string)internalProjectItem;

                if (path == "References")
                {
                    RelativePath  = path;
                    this.itemType = "References";
                }
                else
                {
                    RelativePath = path;
                    FilePath     = Path.Combine(Path.GetDirectoryName(project.FileName), path);

                    if (File.Exists(FilePath))
                    {
                        this.itemType = "File";
                    }
                    else
                    {
                        this.itemType = "Folder";
                    }
                }

                this.project     = project;
                this.HasMetadata = false;
                this.Include     = null;
                this.Hash        = this.RelativePath.GetHash();
            }
            else
            {
                this.itemType            = s_ProjectItemElement_ItemType.GetValue(internalProjectItem, null) as string;
                this.Include             = s_ProjectItemElement_Include.GetValue(internalProjectItem, null) as string;
                this.HasMetadata         = (bool)s_ProjectItemElement_HasMetadata.GetValue(internalProjectItem, null);
                this.project             = project;
                this.internalProjectItem = internalProjectItem;

                file = new FileInfo(project.FileName);

                metadata = s_ProjectItemElement_Metadata.GetValue(internalProjectItem, null) as ICollection <ProjectMetadataElement>;

                if (this.itemType != "ProjectConfiguration")
                {
                    if (this.itemType == "WebReferenceUrl" || this.itemType == "Reference")
                    {
                        var hintPath = metadata.SingleOrDefault(m => m.Name == "HintPath");

                        if (hintPath != null)
                        {
                            RelativePath = hintPath.Value;
                        }

                        FilePath = this.Include.RemoveSurroundingSlashes();
                    }
                    else
                    {
                        if (this.itemType != "SchemaFiles" && this.itemType != "WebReferenceUrl")
                        {
                            try
                            {
                                var include    = this.Include.RemoveSurroundingSlashes();
                                var pattern    = string.Format(@"(?<variable>\$\((?<value>{0})\))", StringExtensions.REGEX_IDENTIFIER_MIDSTRING);
                                var hasErrors  = true;
                                var errorCount = 0;

                                while (hasErrors)
                                {
                                    hasErrors = false;

                                    if (include.RegexIsMatch(pattern))
                                    {
                                        var regex    = new Regex(pattern);
                                        var match    = regex.Match(include);
                                        var variable = match.Groups["variable"].Value;
                                        var value    = match.Groups["value"].Value;

                                        if (this.ParentProject.Properties.Any(p => p.Name == value))
                                        {
                                            var property      = this.ParentProject.Properties.Single(p => p.Name == value);
                                            var propertyValue = property.Value;

                                            propertyValue = propertyValue.Replace("$(MSBuildThisFileDirectory)", Path.GetDirectoryName(this.ParentProject.FileName) + @"\");

                                            include = include.RegexReplace(pattern, propertyValue);
                                        }
                                        else
                                        {
                                            include = include.Replace("$(MSBuildThisFileDirectory)", Path.GetDirectoryName(this.ParentProject.FileName) + @"\");
                                        }
                                    }

                                    errorCount++;

                                    if (errorCount > 10)
                                    {
                                        DebugUtils.Break();
                                    }
                                }

                                RelativePath = include;
                                FilePath     = Path.GetFullPath(Path.Combine(file.DirectoryName, RelativePath));
                            }
                            catch (Exception ex)
                            {
                                FilePath = ex.Message;
                            }
                        }
                    }
                }
            }

            this.IsHidden   = isHidden;
            this.InstanceId = Guid.NewGuid();

            try
            {
                if (this.itemType != "SchemaFiles" && this.itemType != "WebReferenceUrl")
                {
                    UpdateInfo();
                }
            }
            catch
            {
            }

            childItems = new List <IVSProjectItem>();

            if (parentItem != null)
            {
                this.ParentItem = parentItem;
                parentItem.AddChild(this);
            }
        }
예제 #2
0
 public bool Equals(VSProject project)
 {
     return(project.Hash == this.Hash);
 }