本文整理汇总了C#中Microsoft.VisualStudio.Package.ProjectElement.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectElement.GetAttribute方法的具体用法?C# ProjectElement.GetAttribute怎么用?C# ProjectElement.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.Package.ProjectElement
的用法示例。
在下文中一共展示了ProjectElement.GetAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNode
/// <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: GetReferencedLibraryName
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: AddReference
/// <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);
}