首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用DllImport找不到VSIX

用DllImport找不到VSIX
EN

Stack Overflow用户
提问于 2013-08-03 18:08:20
回答 3查看 982关注 0票数 6

我有一个VSIX扩展,它依赖于从非托管DLL部署的代码。我在VSIX中包含了DLL,我用一个zip程序打开了VSIX,以确认它的部署是否正确。但是,当我使用DllImport属性时,.NET框架声称它找不到它。如何从打包在VSIX中的DLL导入函数?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-08-10 00:28:37

我不知道这里出了什么问题,但是我重新安装了Windows和Visual,没有对项目做任何更改,现在一切都很好。在为其他应用程序查找DLL时,我遇到了一些其他问题,我想它们是相关的,我一定是搞砸了一些设置。

票数 3
EN

Stack Overflow用户

发布于 2013-08-07 17:02:00

Windows无法打开嵌入到压缩.zip中的DLL文件,因此您必须将其解压并放入您可以写入的文件夹中。

.NET框架将在%LocalAppData%中查找DLL的路径,因此在那里解压DLL是合理的。

票数 2
EN

Stack Overflow用户

发布于 2013-08-10 05:30:00

在看似随机的情况下,我经常会遇到虚假的包装载故障。这些问题主要影响多个DLL文件的扩展名。通过将[ProvideBindingPath]属性应用于扩展中提供的主Package,最终解决了这些问题。

您需要在项目中包含该属性的源。

代码语言:javascript
复制
/***************************************************************************

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));
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18035790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档