本文整理汇总了C#中IVsHierarchy.GetGuidProperty方法的典型用法代码示例。如果您正苦于以下问题:C# IVsHierarchy.GetGuidProperty方法的具体用法?C# IVsHierarchy.GetGuidProperty怎么用?C# IVsHierarchy.GetGuidProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsHierarchy
的用法示例。
在下文中一共展示了IVsHierarchy.GetGuidProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjectGuid
public Guid GetProjectGuid(IVsHierarchy projectHierarchy)
{
var VSITEMID_ROOT = 0xFFFFFFFE;
Guid projectGuid;
int hr;
hr = projectHierarchy.GetGuidProperty(VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
ErrorHandler.ThrowOnFailure(hr);
return projectGuid;
}
示例2: ProjectTargetView
/// <summary>
/// Create a ProjectTargetView with values from an EnvDTE.Project.
/// </summary>
public ProjectTargetView(IVsHierarchy project) {
object value;
ErrorHandler.ThrowOnFailure(project.GetProperty(
(uint)VSConstants.VSITEMID.Root,
(int)__VSHPROPID.VSHPROPID_Name,
out value
));
_name = value as string ?? "(Unknown name)";
ErrorHandler.ThrowOnFailure(project.GetGuidProperty(
(uint)VSConstants.VSITEMID.Root,
(int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
out _guid
));
}
示例3: WalkSourceProjectAndAdd
/// <summary>
/// Recursive method that walk a hierarchy and add items it find to our project.
/// Note that this is meant as an helper to the Copy&Paste/Drag&Drop functionality.
/// </summary>
/// <param name="sourceHierarchy">Hierarchy to walk</param>
/// <param name="itemId">Item ID where to start walking the hierarchy</param>
/// <param name="targetNode">Node to start adding to</param>
/// <param name="addSibblings">Typically false on first call and true after that</param>
private bool WalkSourceProjectAndAdd(IVsHierarchy sourceHierarchy, uint itemId, string targetPath, bool addSiblings, List<Addition> additions, string name = null) {
Utilities.ArgumentNotNull("sourceHierarchy", sourceHierarchy);
if (itemId != VSConstants.VSITEMID_NIL) {
// Before we start the walk, add the current node
object variant = null;
// Calculate the corresponding path in our project
string source;
ErrorHandler.ThrowOnFailure(((IVsProject)sourceHierarchy).GetMkDocument(itemId, out source));
if (name == null) {
name = CommonUtils.GetFileOrDirectoryName(source);
}
Guid guidType;
ErrorHandler.ThrowOnFailure(sourceHierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out guidType));
IVsSolution solution = Project.GetService(typeof(IVsSolution)) as IVsSolution;
if (solution != null) {
if (guidType == VSConstants.GUID_ItemType_PhysicalFile) {
string projRef;
ErrorHandler.ThrowOnFailure(solution.GetProjrefOfItem(sourceHierarchy, itemId, out projRef));
var addition = CanAddFileFromProjectReference(projRef, targetPath);
if (addition == null) {
// cancelled
return false;
}
additions.Add(addition);
}
}
// Start with child nodes (depth first)
if (guidType == VSConstants.GUID_ItemType_PhysicalFolder) {
variant = null;
ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out variant));
uint currentItemID = (uint)(int)variant;
List<Addition> nestedAdditions = new List<Addition>();
string newPath = Path.Combine(targetPath, name);
if (!WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, newPath, true, nestedAdditions)) {
// cancelled
return false;
}
if (!Project.Tracker.CanRenameItem(
source,
newPath,
VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory)) {
return false;
}
additions.Add(new FolderAddition(Project, Path.Combine(targetPath, name), source, DropEffect, nestedAdditions.ToArray()));
}
if (addSiblings) {
// Then look at siblings
uint currentItemID = itemId;
while (currentItemID != VSConstants.VSITEMID_NIL) {
variant = null;
// http://mpfproj10.codeplex.com/workitem/11618 - pass currentItemID instead of itemId
ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(currentItemID, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out variant));
currentItemID = (uint)(int)variant;
if (!WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, targetPath, false, additions)) {
// cancelled
return false;
}
}
}
}
return true;
}
示例4: UpdateServiceDefinition
/// <summary>
/// Updates the ServiceDefinition.csdef file in
/// <paramref name="project"/> to include the default startup and
/// runtime tasks for Python projects.
/// </summary>
/// <param name="project">
/// The Cloud Service project to update.
/// </param>
/// <param name="roleType">
/// The type of role being added, either "Web" or "Worker".
/// </param>
/// <param name="projectName">
/// The name of the role. This typically matches the Caption property.
/// </param>
/// <param name="site">
/// VS service provider.
/// </param>
internal static void UpdateServiceDefinition(
IVsHierarchy project,
string roleType,
string projectName,
System.IServiceProvider site
) {
Utilities.ArgumentNotNull("project", project);
object obj;
ErrorHandler.ThrowOnFailure(project.GetProperty(
(uint)VSConstants.VSITEMID.Root,
(int)__VSHPROPID.VSHPROPID_FirstChild,
out obj
));
uint id;
while (TryGetItemId(obj, out id)) {
Guid itemType;
string mkDoc;
if (ErrorHandler.Succeeded(project.GetGuidProperty(id, (int)__VSHPROPID.VSHPROPID_TypeGuid, out itemType)) &&
itemType == VSConstants.GUID_ItemType_PhysicalFile &&
ErrorHandler.Succeeded(project.GetProperty(id, (int)__VSHPROPID.VSHPROPID_Name, out obj)) &&
"ServiceDefinition.csdef".Equals(obj as string, StringComparison.InvariantCultureIgnoreCase) &&
ErrorHandler.Succeeded(project.GetCanonicalName(id, out mkDoc)) &&
!string.IsNullOrEmpty(mkDoc)
) {
// We have found the file
var rdt = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
IVsHierarchy docHier;
uint docId, docCookie;
IntPtr pDocData;
bool updateFileOnDisk = true;
if (ErrorHandler.Succeeded(rdt.FindAndLockDocument(
(uint)_VSRDTFLAGS.RDT_EditLock,
mkDoc,
out docHier,
out docId,
out pDocData,
out docCookie
))) {
try {
if (pDocData != IntPtr.Zero) {
try {
// File is open, so edit it through the document
UpdateServiceDefinition(
Marshal.GetObjectForIUnknown(pDocData) as IVsTextLines,
roleType,
projectName
);
ErrorHandler.ThrowOnFailure(rdt.SaveDocuments(
(uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_ForceSave,
docHier,
docId,
docCookie
));
updateFileOnDisk = false;
} catch (ArgumentException) {
} catch (InvalidOperationException) {
} catch (COMException) {
} finally {
Marshal.Release(pDocData);
}
}
} finally {
ErrorHandler.ThrowOnFailure(rdt.UnlockDocument(
(uint)_VSRDTFLAGS.RDT_Unlock_SaveIfDirty | (uint)_VSRDTFLAGS.RDT_RequestUnlock,
docCookie
));
}
}
if (updateFileOnDisk) {
// File is not open, so edit it on disk
FileStream stream = null;
try {
UpdateServiceDefinition(mkDoc, roleType, projectName);
} finally {
//.........这里部分代码省略.........
示例5: GetProjectReferenceOnNodeForHierarchy
private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references,
IVsHierarchy inputHierarchy)
{
if (references == null)
{
return null;
}
Guid projectGuid;
ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
(int) __VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));
string canonicalName;
ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
foreach (var refNode in references)
{
var projRefNode = refNode as ProjectReferenceNode;
if (projRefNode != null)
{
if (projRefNode.ReferencedProjectGuid == projectGuid)
{
return projRefNode;
}
// Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
if (!string.IsNullOrEmpty(projRefNode.Url) &&
NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
{
return projRefNode;
}
}
}
return null;
}
示例6: ProcessHierarchyNode
private void ProcessHierarchyNode(IVsHierarchy hierarchy, uint itemid)
{
int hr;
// Canonical Name
string canonicalName;
hr = hierarchy.GetCanonicalName(itemid, out canonicalName);
// Project Name
object projectName;
ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out projectName));
// Project GUID
Guid projectGuid;
hr = hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid);
if (Guid.Empty == projectGuid) // in case when project is unloaded
_projectNames.TryGetValue(canonicalName, out projectGuid);
// Project Icon
var icon = RetrieveProjectIcon(hierarchy);
// Load Priority
var loadPriority = RetrieveProjectLoadPriority(projectGuid);
if (null == _rootProject)
{
_rootProject = _lastProject = new ProjectInfo((String)projectName, projectGuid, loadPriority, null) { Icon = icon };
}
else
{
_lastProject = new ProjectInfo((String)projectName, projectGuid, loadPriority, _currentProject) { Icon = icon };
_currentProject.Children.Add(_lastProject);
}
}
示例7: GetProjectType
static public Guid GetProjectType(IVsHierarchy hierarchy)
{
Guid projectType = Guid.Empty;
if (hierarchy != null) {
hierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projectType);
}
return projectType;
}
示例8: getProjectNameFrom
/// <param name="pHierProj"></param>
/// <param name="force">Load in global collection with __VSHPROPID.VSHPROPID_ExtObject if true value</param>
/// <returns>project name from Microsoft.Build.Evaluation rules or null value if project not found in GlobalProjectCollection and force value is false</returns>
public string getProjectNameFrom(IVsHierarchy pHierProj, bool force = false)
{
Guid id;
pHierProj.GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out id);
foreach(Project eProject in ProjectCollection.GlobalProjectCollection.LoadedProjects)
{
string guidString = eProject.GetPropertyValue("ProjectGuid");
if(!String.IsNullOrEmpty(guidString) && id == (new Guid(guidString))) {
return getProjectNameFrom(eProject);
}
}
if(!force) {
return null;
}
object dteProject;
pHierProj.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out dteProject);
return getProjectNameFrom(tryLoadPCollection((EnvDTE.Project)dteProject));
}
示例9: GetProjectReferenceOnNodeForHierarchy
private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references, IVsHierarchy inputHierarchy)
{
if(references == null)
return null;
Guid projectGuid;
// !EFW - This is an odd one. Open a file not contained within a project in the active solution and
// then close it. When you do, this method is called and it fails here. The file is hosted in the
// Miscellaneous Files hierarchy. In such cases, we'll just ignore it and return null.
if(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT,
(int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid) != VSConstants.S_OK)
return null;
string canonicalName;
ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
foreach(ReferenceNode refNode in references)
{
ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
if(projRefNode != null)
{
if(projRefNode.ReferencedProjectGuid == projectGuid)
return projRefNode;
// Try with canonical names, if the project that is removed is an unloaded project that the
// above criteria will not pass.
if(!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
return projRefNode;
}
}
return null;
}