예제 #1
0
        /// <include file='doc\Project.uex' path='docs/doc[@for="Project.CreateNode"]/*' />
        protected virtual HierarchyNode CreateNode(Project root, HierarchyNodeType type, ProjectElement item)
        {
            if (type == HierarchyNodeType.File)
            {
                HierarchyItemNode hi = new HierarchyItemNode(this, type, item);

                if (NodeHasDesigner(item.GetAttribute("Include")))
                {
                    hi.HasDesigner = true;
                }

                return hi;
            }

            return new HierarchyNode(root, type, item);
        }
예제 #2
0
        string GetReferencedLibraryName(ProjectElement assemblyRefNode)
        {
            string assembly = assemblyRefNode.GetAttribute("AssemblyName");

            if (!assembly.ToLower().EndsWith(".dll"))
                assembly += ".dll";

            string hint = assemblyRefNode.GetAttribute("HintPath");

            if (hint != "" && hint != null)
            {
                Url url = new Url(new Url(this.ProjectFolder + "/"), hint);
                assembly = url.AbsoluteUrl;

                if (!File.Exists(assembly))
                {
                    url = new Url(new Url(GetSystemAssemblyPath() + "/"), hint);
                    assembly = url.AbsoluteUrl;
                }
            }

            if (!File.Exists(assembly))
            {
                assembly = this.GetFullyQualifiedNameForReferencedLibrary(this.GetProjectOptions(null), assembly);
            }

            return assembly;
        }
예제 #3
0
        /// <include file='doc\Project.uex' path='docs/doc[@for="Project.AddReference"]/*' />
        public virtual void AddReference(string name, string path)
        {
            string newFile = name;
            int extensionStart = newFile.LastIndexOf('.');
            if (extensionStart>0 && String.Compare(".dll", newFile.Substring(extensionStart), true, CultureInfo.InvariantCulture) == 0)
                newFile = newFile.Substring(0, extensionStart);

            // first check if this guy is already in it...
            foreach (MSBuild.Item item in this.projFile.GetEvaluatedItemsByType("Reference"))
            {
                ProjectElement reference = new ProjectElement(this, item, false);
                string file = reference.GetAttribute("AssemblyName");
                if (file == null && file.Length == 0)
                    file = reference.GetAttribute("Include");

                if (String.Compare(newFile, file) == 0)
                {
                    //TODO: provide a way for an extender to issue a message here
                    return;
                }
            }
            // need to insert the reference into the reference list of the project document for persistence
            ProjectElement newItem = this.CreateFileNode(name, "Reference");

            // extract the assembly name out of the absolute filename
            string assemblyNameNoExtension = name;
            try
            {
                assemblyNameNoExtension = Path.GetFileNameWithoutExtension(name);
            }
            catch {}

            newItem.SetAttribute("Name", assemblyNameNoExtension);
            newItem.SetAttribute("AssemblyName", name);

            string hintPath = null;
            InitPrivateAttribute(path, newItem);
            try
            {
                // create the hint path. If that throws, no harm done....
                Uri hintURI = new Uri(path);
                Uri baseURI = this.BaseURI.Uri;
                string diff = baseURI.MakeRelative(hintURI);
                // MakeRelative only really works if on the same drive.
                if (hintURI.Segments[1] == baseURI.Segments[1])
                {
                    diff = diff.Replace('/', '\\');
                }
                else
                {
                    diff = hintURI.LocalPath;
                }

                hintPath = diff;
            }
            catch (System.Exception ex)
            {
                CCITracing.Trace(ex);
                CCITracing.TraceData(path);
                CCITracing.TraceData(this.BaseURI.AbsoluteUrl);
            }
            if (hintPath != null)
                newItem.SetAttribute("HintPath", hintPath);

            // At this point force the item to be refreshed
            newItem.RefreshProperties();

            // need to put it into the visual list
            HierarchyNode node = CreateNode(this.projectMgr, HierarchyNodeType.Reference, newItem);

            referencesFolder.AddChild(node);
            this.OnAddReferenceNode(node);
        }