Don't know that I like the answer. Looks like it will break with future
versions of the IDE. Not something that I want to do right now.
"Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
news:g7bcoY1MFHA.3944@TK2MSFTNGXA03.phx.gbl...
> Thanks for all your informative inputs.
>
> Hi Andrew,
>
> As for accessing web.config's settings at Design-time, there hasn't any
> buildin API like the System.Configuration.... we used at runtime. However,
> we can use the VS.NET's design-time interfaces to locate the project's
> folder and then read any files in that folder(Read the web.config as a
> normal xml file). Here is a former thread discussing on such question:
>
> #Getting Project Folder during Design Time
>
http://groups.google.com/groups?hl=zh-CN&lr=&threadm=uqDHTrtdEHA.3988%40tk2m
>
sftngp13.phx.gbl&rnum=1&prev=/groups%3Fhl%3Dzh-CN%26lr%3D%26q%3D%2523%2BGett
> ing%2BProject%2BFolder%2Bduring%2BDesign%2BTime
>
>
> here are some similiar VB.NET code :
>
> [VB.Net]
> Imports System.ComponentModel
> Imports System.Runtime.InteropServices
>
> Module DTEUtilsModule DTEUtils
>
> Public ReadOnly VS2002MonikerBase As String = "!VisualStudio.DTE.7:"
> Public ReadOnly VS2003MonikerBase As String =
> "!VisualStudio.DTE.7.1:"
>
> Public Enum VisualStudioVersionEnum VisualStudioVersion
> [VS2002]
> [VS2003]
> End Enum
>
> Private Class Win32APIClass Win32API
> <DllImport("ole32.dll")> _
> Public Shared Function GetRunningObjectTable()Function
> GetRunningObjectTable(ByVal reserved As
> Integer, <Out()> ByRef prot As UCOMIRunningObjectTable) As Integer
> End Function
>
> <DllImport("ole32.dll")> _
> Public Shared Function CreateBindCtx()Function CreateBindCtx(ByVal
> reserved As Integer,
> <Out()> ByRef ppbc As UCOMIBindCtx) As Integer
> End Function
> End Class
>
> Public Overloads Function GetVisualStudioMoniker()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()Function
> GetVisualStudioMoniker() As String
> Return GetVisualStudioMoniker(VisualStudioVersion.VS2002)
> End Function
>
> Public Function GetDTE()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()Function GetProjectUrl() As
> String
> Return GetProjectUrl(GetDTE())
> End Function
>
> Public Overloads Function GetProjectUrl()Function GetProjectUrl(ByVal
> DTE As Object) As
> 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()Function
> GetProjectLocalPath() As String
> Return GetProjectLocalPath(GetDTE())
> End Function
>
> Public Overloads Function GetProjectLocalPath()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()Function GetMSDEVFromGIT(ByVal
> strProgID As String) As Object
>
> Dim prot As UCOMIRunningObjectTable
> Dim pMonkEnum As UCOMIEnumMoniker
>
> Win32API.GetRunningObjectTable(0, prot)
> prot.EnumRunning(pMonkEnum)
> pMonkEnum.Reset()
>
> Dim fetched As Integer
>
> Dim pmon(1) As UCOMIMoniker
>
>
> While pMonkEnum.Next(1, pmon, fetched) = 0
> Dim pCtx As UCOMIBindCtx
> Win32API.CreateBindCtx(0, pCtx)
>
> Dim str As String
> pmon(0).GetDisplayName(pCtx, Nothing, str)
>
> 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()Function GetCurrentWebFormUrl()
>
> Dim svc As IWebFormsDocumentService =
> Me.GetService(GetType(IWebFormsDocumentService))
> Return svc.DocumentUrl
>
> End Function
>
> End Module
>
>
> HTH. Thanks,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure!
www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>