惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
D
Docker
Jina AI
Jina AI
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
爱范儿
爱范儿
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
Recent Announcements
Recent Announcements
U
Unit 42
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
量子位
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 阿兰德隆

技术文章杂项罗列-1 ASP.NET CLIENTSIDE BEHAVIORS WSS Generic tech tutorials DATA concurrency in ADO.NET ASP.NET Browser compatibility related reference ***Internationalization related tech articles*** .net common utility frameworks WINFORM develop tech articles and tutorials VC++ third party shared components #Good EBook Download Sites ASP.NET Web Server Control 开发系列 工具系列 XML 相关技术 ASP.NET Performance Related Tech Reference Office document manipulation tech articles ASP.NET 第三方控件系列 层次型嵌套数据绑定以及关联数据插入模式 .NET 开发者10件必备武器:) ASP.NET BUILDIN FILEUPLOAD ISSUE
VS.NET DESIGN-TIME Issues
阿兰德隆 · 2004-08-02 · via 博客园 - 阿兰德隆

#VS.NET Design-time 获取当前的Project得目录路径
http://www.cnblogs.com/jonnyyu/archive/2004/02/20/1439.aspx?Pending=true#Post

#VB.NET 类似代码片断:

[VB.Net]
Imports System.ComponentModel
Imports System.Runtime.InteropServices

Module DTEUtils

    
Public ReadOnly VS2002MonikerBase As String = "!VisualStudio.DTE.7:"
    Public ReadOnly VS2003MonikerBase As String =
"!VisualStudio.DTE.7.1:"

    Public Enum VisualStudioVersion
        [VS2002]
        [VS2003]
    
End Enum


    
Private Class Win32API
        
<DllImport("ole32.dll")> _
        
Public Shared Function GetRunningObjectTable(ByVal reserved As
Integer<Out()> ByRef prot As UCOMIRunningObjectTable) As Integer
        
End Function


        
<DllImport("ole32.dll")> _
        
Public Shared Function CreateBindCtx(ByVal reserved As Integer,
<Out()> ByRef ppbc As UCOMIBindCtx) As Integer
        
End Function

    
End Class


    
Public Overloads Function GetVisualStudioMoniker(ByVal version As
VisualStudioVersion) 
As String
        
Dim strBase As String

        
Select Case version
            
Case VisualStudioVersion.VS2002
                strBase 
= VS2002MonikerBase
            
Case VisualStudioVersion.VS2003
                strBase 
= VS2003MonikerBase
        
End Select

        
Return strBase &
System.Diagnostics.Process.GetCurrentProcess().Id.ToString()
    
End Function


    
Public Overloads Function GetVisualStudioMoniker() As String
        
Return GetVisualStudioMoniker(VisualStudioVersion.VS2002)
    
End Function


    
Public Function GetDTE() As Object
        
Dim strMoniker As String =
GetVisualStudioMoniker(VisualStudioVersion.VS2002)
        
Dim objDTE As Object = GetMSDEVFromGIT(strMoniker)

        
If objDTE Is Nothing Then
            strMoniker 
=
GetVisualStudioMoniker(VisualStudioVersion.VS2003)
            objDTE 
= GetMSDEVFromGIT(strMoniker)
        
End If

        
Return objDTE
    
End Function


    
Public Overloads Function GetProjectUrl() As String
        
Return GetProjectUrl(GetDTE())
    
End Function


    
Public Overloads Function GetProjectUrl(ByVal DTE As ObjectAs
String
        
Dim strUrl As String

        
Try
            
Dim projs() As Object = DTE.ActiveSolutionProjects
            
Dim proj As Object = projs(0)
            strUrl 
= proj.Properties.Item("URL").Value
        
Catch exc As Exception
            Console.
WriteLine(exc.Message,
exc.GetBaseException.
GetType.Name)
            Console.
WriteLine(exc.StackTrace)
        
End Try

        
If Right(strUrl, 1= "/" Then strUrl = Left(strUrl, Len(strUrl)
- 1)

        
Return strUrl
    
End Function



    
Public Overloads Function GetProjectLocalPath() As String
        
Return GetProjectLocalPath(GetDTE())
    
End Function


    
Public Overloads Function GetProjectLocalPath(ByVal DTE As Object)
As String
        
Dim strPath As String

        
Try
            
Dim projs() As Object = DTE.ActiveSolutionProjects
            
Dim proj As Object = projs(0)
            strPath 
= proj.Properties.Item("LocalPath").Value
        
Catch exc As Exception
            Console.
WriteLine(exc.Message,
exc.GetBaseException.
GetType.Name)
            Console.
WriteLine(exc.StackTrace)
        
End Try

        
If Right(strPath, 1= "/" Then strPath = Left(strPath,
Len(strPath) - 1)

        
Return strPath
    
End Function



    
Public Function GetMSDEVFromGIT(ByVal strProgID As StringAs Object

        
Dim prot As UCOMIRunningObjectTable
        
Dim pMonkEnum As UCOMIEnumMoniker

        Win32API.GetRunningObjectTable(
0, prot)
        prot.EnumRunning(pMonkEnum)
        pMonkEnum.
Reset()

        
Dim fetched As Integer

        
Dim pmon(1As UCOMIMoniker


        
While pMonkEnum.Next(1, pmon, fetched) = 0
            
Dim pCtx As UCOMIBindCtx
            Win32API.CreateBindCtx(
0, pCtx)

            
Dim str As String
            pmon(
0).GetDisplayName(pCtx, Nothingstr)

            
If str = strProgID Then
                
Dim objReturnObject As Object
                prot.
GetObject(pmon(0), objReturnObject)
                
Return objReturnObject

            
End If

        
End While

        
Return Nothing

    
End Function



Public Function GetCurrentWebFormUrl()

       
Dim svc As IWebFormsDocumentService =
       Me.GetService(
GetType(IWebFormsDocumentService))
       
Return svc.DocumentUrl

End Function


End Module