c# - 调试时 VS2012 的 VSIX 扩展未运行

标签 c# debugging visual-studio-2012 vsix

我在 Visual Studio 2012 中创建了一个新的 VSIX 扩展项目,并编写了一个 MEF 分类器(作为测试),它应该简单地突出显示 .mylang 中的所有文本。文件。以下是我的 .NET 4.5 代码的相关部分:

internal static class MyLangLanguage
{
    public const string ContentType = "mylang";

    public const string FileExtension = ".mylang";

    [Export(typeof(ClassificationTypeDefinition))]
    [Name(ContentType)]
    [BaseDefinition("code")]
    internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;

    [Export]
    [FileExtension(FileExtension)]
    [ContentType(ContentType)]
    internal static FileExtensionToContentTypeDefinition MyLangSyntaxFileExtensionDefinition = null;
}

[Export(typeof(IClassifierProvider))]
[ContentType(MyLangLanguage.ContentType)]
[Name("MyLangSyntaxProvider")]
internal sealed class MyLangSyntaxProvider : IClassifierProvider
{
    [Import]
    internal IClassificationTypeRegistryService ClassificationRegistry = null;

    public IClassifier GetClassifier(ITextBuffer buffer)
    {
        return buffer.Properties.GetOrCreateSingletonProperty(() => new MyLangSyntax(ClassificationRegistry, buffer));
    }
}

internal sealed class MyLangSyntax : IClassifier { }

Here is the full code .

这些是我的 source.extension.vsixmanifest 的相关部分文件。根据我在网上找到的建议和类似文件,我添加了对 MPF 和两个 Assets 的依赖。

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
    <!-- ... -->
    <Dependencies>
        <Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="4.5" />
        <Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" Version="[11.0,12.0)" />
    </Dependencies>
    <Assets>
        <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
        <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
    </Assets>
</PackageManifest>

我还尝试了 1.0 版 list :

<?xml version="1.0" encoding="utf-8"?>
<Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
    <!-- ... -->
    <References />
    <Content>
        <MefComponent>|%CurrentProject%|</MefComponent>
    </Content>
</Vsix>

当我运行它时,它会启动 Visual Studio 2012 的实验实例,并且扩展和更新 窗口显示我的扩展处于事件状态。但是,当我加载或创建 .mylang 文件时,它不会执行任何操作。我从扩展中抛出的任何异常(作为测试)都不会抛出。永远不会命中断点,并得到带有以下警告的感叹号:

The breakpoint will not currently be hit. No symbols have been loaded for this document.

感觉好像我的扩展根本就没有真正加载过。我的问题类似于 this problemthis problem ,但我使用的是 Visual Studio 2012,它使用新的 VSIX list 格式。

我所知道的:

  • 我可以在 %localappdata%\Microsoft\VisualStudio\11.0Exp\Extensions\MyLang\VSIXProject1\1.0 中找到我的 DLL 和 VSIX 文件文件夹,所以我知道它们已被复制。
  • 它们的时间戳对应于我上次构建项目的时间,所以我知道它们是最新的。
  • 项目属性 > 调试 > 启动外部程序: 已自动设置为 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe ,并且命令行参数被自动设置为/rootsuffix Exp .
  • Visual Studio 日志(使用 /log 选项创建)有两个与我的扩展相关的条目:Successfully loaded extension...Extension is enabled... .
  • 我的 DLL 没有出现在调试 Visual Studio 的模块选项卡(所有加载的 DLL 的列表)中,而一些(不是全部)其他扩展 确实出现了。
  • 它不会在我的笔记本电脑和台式电脑上的 Visual Studio 2012 或 2010 中加载。

我尝试过的:

  • 设置<IncludeAssemblyInVSIXContainer>true.csproj 文件中,根据 this suggestion , 但它没有任何区别。
  • 不能添加行 <MefComponent>|%CurrentProject%|</MefComponent>source.extension.vsixmanifest 文件,因为它使用与以前版本的 Visual Studio (1.0) 的 VSIX 项目不同的格式 (2.0)。
  • This suggestion (将 IncludeAssemblyInVSIXContainer 和我的 .csproj 中的 friend 设置为 true )但这并没有什么区别。而且我的断点仍然显示警告,没有被击中。
  • 使用“开始”菜单中的重置 Visual Studio 2012 实验实例 快捷方式重置 VS 实验实例,根据 this suggestion .这没有什么不同。

至少我如何才能确定我的 VSIX MEF 扩展已加载并正常工作?如果可能的话,我怎样才能通过断点工作并调试它?

最佳答案

编辑:问题是您不正确地将ContentTypeDefinition 导出为ClassificationTypeDefinition。您应该改用以下内容:

[Export] // <-- don't specify the type here
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;

这是我现在的两个猜测:

  1. 尝试从您的 vsixmanifest 中删除以下行。我假设您的项目中没有扩展 Package 的类,在这种情况下,Visual Studio 可能会因为以下 Assets 行而拒绝加载您的包(您的扩展实际上并不提供此 Assets )。

    <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
    
  2. 如果失败,请尝试将当前的 source.extension.vsixmanifest 替换为写入旧架构(1.0 版)的 list 。我知道这种形式在 Visual Studio 2012 中仍然有效,因为我处理的所有约 20 个扩展(超过 10 个公开版本)都使用旧架构。

关于c# - 调试时 VS2012 的 VSIX 扩展未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16422004/

相关文章:

msbuild - 在解决方案中使用多个网站项目进行持续部署

c# - 在哪里可以找到新的 Span<T>?

ruby-on-rails - Rails验证或可能的路由错误

javascript - Firebug v2.0.1 在旧断点处中断

debugging - 我可以将哪些标志或环境变量传递给 Clang 以在 BSD 和 Linux 上进行最大程度的调试?

database - 在 VB.NET 中使用 OLEDB 通过 DataGridView 更新 Access 数据库

c++ - 它有助于在 C++ 中将方法标记为内联吗?

c# - 在 List<string> 中搜索字符串 .StartsWith()

c# - CS1106 扩展方法必须在非泛型静态类中定义

c# - 将菜单项添加到另一个应用程序