2010-01-24 1 views
0

참조 된 DLL에서 Application.StartupPath를 사용하는 경우 경로는 IDE의 경로를 가리 킵니다.winforms, .net에서 디자인 타임에 응용 프로그램 경로를 얻는 방법?

어쨌든 실제 응용 프로그램의 경로를 얻을 수 있습니까?

이것은 분명히 밝혀졌습니다. 디자인 타임입니다.

ETA : 나는 아래의 솔루션을 게시 한 :

, η2 :이 관련이 있기 때문에, 나는 또 다른 유용한 디자인 타임 서비스의 조각을 게시 할 거라고 생각

. 아래의 솔루션과 마찬가지로이 예는 UITypeEditor 용입니다.

Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object 

    Dim typeDiscovery As ITypeDiscoveryService = TryCast(provider.GetService(GetType(ITypeDiscoveryService)), ITypeDiscoveryService) 
    Dim types As ICollection = typeDiscovery.GetTypes(GetType(MyType), False) 

End Function 

유형에는 MyType에서 파생 된 모든 유형이 포함됩니다. GAC 검색을 제외하려면 두 번째 매개 변수를 True로 변경하십시오. 모든 유형의 목록을 가져 오는 첫 번째 매개 변수로 Nothing을 전달하십시오.

답변

0

다음은 UITypeEditor에서 수행하는 방법입니다.

ETA : 원본 코드에 불필요한 추가 단계가 있습니다. 우리는 서비스 제공 업체를 잊어 버렸기 때문에 사이트를 볼 필요가 없습니다. 유선형의 코드는 다음과 같습니다

Public Class MyEditor 
    Inherits UITypeEditor 

    Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object 

     Dim typeRes As ITypeResolutionService = TryCast(provider.GetService(GetType(ITypeResolutionService)), ITypeResolutionService) 
     Dim ass As System.Reflection.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName() 
     MessageBox.Show(ass.CodeBase, "Design-time Path") 
     MessageBox.Show(typeRes.GetPathOfAssembly(ass), "Run-time Path") 

    End Function 

End Class 

원본 코드 :이 솔루션은 풍부한 정보를 찾을 수 있습니다 How to: Access Design-Time Services에서 코드를 기반으로

Public Class MyEditor 
    Inherits UITypeEditor 

    Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object 

     Dim component As IComponent = TryCast(context.Instance, IComponent) 
     Dim site As ISite = component.Site 
     Dim typeRes As ITypeResolutionService = TryCast(site.GetService(GetType(ITypeResolutionService)), ITypeResolutionService) 
     Dim ass As System.Reflection.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName() 
     MessageBox.Show(ass.CodeBase, "Design-time Path") 
     MessageBox.Show(typeRes.GetPathOfAssembly(ass), "Run-time Path") 

    End Function 

End Class 

.

-1

당신은 디자인 타임에 그것을 할 수 없습니다! 런타임시, 즉, 응용 프로그램을 빌드하고 실행하거나 VS 내에서 F5를 누르거나 녹색 화살표를 클릭하면됩니다. 왜 디자인 타임에 알고 싶습니까? 실행 파일과 관련 DLL이 실제로 메모리에로드되고 실행되지 않으며, 코드가 변경되면 전체 프로젝트를 다시 빌드해야하기 때문에 관련성이 없습니다.

호프가 도움이 되었으면 안녕하세요, 탐.

+0

안녕하세요, ITypeResolutionService.GetPathOfAssembly를 사용하여이 작업을 수행 할 수 있습니다. 참조 : http://msdn.microsoft.com/en-us/library/ms171822%28VS.80%29.aspx. 나는 지금 그것을 소화 할 시간이 없지만 내일 또 다른 모습을 보일 것이며 아무도 먼저 도착하지 않으면 해결책을 게시 할 것입니다. – Jules

+0

소화하고, 해결책을 추가했습니다 – Jules

+1

@Jules : 저것을 ... 감사합니다. :) – t0mm13b