2013-08-03 3 views
6

관리되지 않는 DLL에서 배포 한 코드에 따라 달라지는 VSIX 확장자가 있습니다. VSIX에 DLL을 포함 시켰고 zip 프로그램으로 VSIX를 열어 올바르게 배포되었는지 확인했습니다. 그러나 DllImport 특성을 사용하면 .NET Framework에서 해당 특성을 찾을 수 없다고 주장합니다. 내 VSIX에 패키지 된 DLL에서 함수를 어떻게 가져올 수 있습니까?DllImport가있는 VSIX dll을 찾을 수 없습니다.

+1

경로가 누락 되었습니까? 이게 도움이 되나요? http://stackoverflow.com/a/10800260/71312 – Diryboy

+0

관리되지 않는 dll이 확장 프로그램의 설치 디렉토리에 제대로 추출되었는지 확인 했습니까? 관리되지 않는 DLL을 호출하는 셸 패키지를 배포하는 간단한 VSIX를 사용했습니다. 콘텐트 빌드 액션으로 관리되지 않는 dll을 프로젝트에 추가하고이를 VSIX에 포함 시켰습니다. 그것은 디버그와 정규 배치 된 확장 모두에서 올바르게 실행됩니다. – WarrenG

+0

@WarrenG : 나는 그것이 어디 있는지 전혀 모른다. 내 DLL에 대한 내 빌드 작업은 "콘텐츠"이기 때문에 VSIX에 포함하도록 설정했습니다. – Puppy

답변

3

여기에 무슨 문제가 있는지 몰라도 Windows와 Visual Studio를 다시 설치하고 프로젝트를 변경하지 않아도됩니다. 다른 응용 프로그램 용 DLL을 찾는 데 몇 가지 다른 문제가 있었지만 관련이 있다고 생각합니다. 설정을 망쳤습니다.

2

Windows는 압축 된 .zip에 포함 된 DLL 파일을 열 수 없으므로 압축을 풀고 쓰기 권한이있는 폴더에 파일을 저장해야합니다.

.NET Framework는 DLL 경로를 %LocalAppData%으로 검색하므로 DLL을 압축 해제하는 것이 좋습니다.

+0

Visual Studio는 VSIX에서 파일을 설치 디렉터리로 추출합니다. – Puppy

+0

이벤트 로그를 열고 패키지가 DLL을로드하려고 시도한 경로를 확인할 수 있습니까? https://en.wikipedia.org/wiki/Event_Viewer –

+0

그리고이 도구가 도움이 될 수 있습니다. http://technet.microsoft.com/en-us/sysinternals/bb896645 –

1

나는 겉보기에 임의의 상황에서 가짜 패키지로드 실패를 얻는 데 사용됩니다. 문제는 주로 하나 이상의 DLL 파일로 구성된 확장에 영향을 미쳤습니다. 마지막으로 확장에 제공된 Package 메인에 [ProvideBindingPath] 속성을 적용하여 문제를 해결했습니다.

프로젝트의 속성 소스를 포함해야합니다.

/*************************************************************************** 

Copyright (c) Microsoft Corporation. All rights reserved. 
This code is licensed under the Visual Studio SDK license terms. 
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY 
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR 
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. 

***************************************************************************/ 

using System; 
using System.Text; 

namespace Microsoft.VisualStudio.Shell 
{ 
    /// <summary> 
    /// This attribute registers a path that should be probed for candidate assemblies at assembly load time. 
    /// 
    /// For example: 
    /// [...\VisualStudio\10.0\BindingPaths\{5C48C732-5C7F-40f0-87A7-05C4F15BC8C3}] 
    ///  "$PackageFolder$"="" 
    ///  
    /// This would register the "PackageFolder" (i.e. the location of the pkgdef file) as a directory to be probed 
    /// for assemblies to load. 
    /// </summary> 
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] 
    public sealed class ProvideBindingPathAttribute : RegistrationAttribute 
    { 
     /// <summary> 
     /// An optional SubPath to set after $PackageFolder$. This should be used 
     /// if the assemblies to be probed reside in a different directory than 
     /// the pkgdef file. 
     /// </summary> 
     public string SubPath { get; set; } 

     private static string GetPathToKey(RegistrationContext context) 
     { 
      return string.Concat(@"BindingPaths\", context.ComponentType.GUID.ToString("B").ToUpperInvariant()); 
     } 

     public override void Register(RegistrationContext context) 
     { 
      if (context == null) 
      { 
       throw new ArgumentNullException("context"); 
      } 

      using (Key childKey = context.CreateKey(GetPathToKey(context))) 
      { 
       StringBuilder keyName = new StringBuilder(context.ComponentPath); 
       if (!string.IsNullOrEmpty(SubPath)) 
       { 
        keyName.Append("\\"); 
        keyName.Append(SubPath); 
       } 

       childKey.SetValue(keyName.ToString(), string.Empty); 
      } 
     } 

     public override void Unregister(RegistrationContext context) 
     { 
      if (context == null) 
      { 
       throw new ArgumentNullException("context"); 
      } 

      context.RemoveKey(GetPathToKey(context)); 
     } 
    } 
} 
+0

그래,하지만 여기서 패키지를로드하는 것에 대해 말하는 것이 아닙니다. 관리되지 않는 DLL과 패키지는 아주 다른 메커니즘을 사용합니다. – Puppy

관련 문제