VS2012的VSIX扩展在调试时不运行 [英] VSIX extension for VS2012 not running when debugging

查看:226
本文介绍了VS2012的VSIX扩展在调试时不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 内部静态类MyLangLanguage 
{
public const string ContentType =mylang;

public const string FileExtension =.mylang;

[Export(typeof(ClassificationTypeDefinition))]
[名称(ContentType)]
[BaseDefinition(code)]
内部静态ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;

[导出]
[FileExtension(FileExtension)]
[ContentType(ContentType)]
内部静态FileExtensionToContentTypeDefinition MyLangSyntaxFileExtensionDefinition = null;
}

[Export(typeof(IClassifierProvider))]
[ContentType(MyLangLanguage.ContentType)]
[Name(MyLangSyntaxProvider)]
内部密封类MyLangSyntaxProvider:IClassifierProvider
{
[Import]
internal IClassificationTypeRegistryService ClassificationRegistry = null;

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

内部密封类MyLangSyntax:IClassifier {}

以下是完整的代码



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

 <?xml version =1.0encoding =utf-8?> 
< PackageManifest Version =2.0.0xmlns =http://schemas.microsoft.com/developer/vsx-schema/2011xmlns:d =http://schemas.microsoft.com/开发人员/ vsx-schema-design / 2011>
<! - ... - >
<依赖关系>
< Dependency Id =Microsoft.Framework.NDPDisplayName =Microsoft .NET Frameworkd:Source =ManualVersion =4.5/>
< Dependency d:Source =InstalledId =Microsoft.VisualStudio.MPF.11.0DisplayName =Visual Studio MPF 11.0Version =[11.0.12.0]/>
< /依赖关系>
<资产>
<资产类型=Microsoft.VisualStudio.VsPackaged:Source =Projectd:ProjectName =%CurrentProject%Path =|%CurrentProject%; PkgdefProjectOutputGroup | />
<资产类型=Microsoft.VisualStudio.MefComponentd:源=项目d:ProjectName =%CurrentProject%Path =|%CurrentProject%| />
< / Assets>
< / PackageManifest>

我还尝试了一个1.0版本的清单:



< pre class =lang-xml prettyprint-override> <?xml version =1.0encoding =utf-8?>
< Vsix版本=1.0.0xmlns =http://schemas.microsoft.com/developer/vsx-schema/2010>
<! - ... - >
<参考文献/>
<内容>
< MefComponent> |%CurrentProject%|< / MefComponent>
< / Content>
< / Vsix>






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


断点当前不会被击中。没有为此文档加载任何符号。


感觉好像我的扩展名从来没有真正加载。我的问题类似于此问题这个问题,但我使用的是Visual Studio 2012,它使用新的VSIX清单格式。



我知道:




  • 我可以在%localappdata%\Microsoft\VisualStudio\11.0Exp\Extensions\中找到我的DLL和VSIX文件MyLang\VSIXProject1\1.0 文件夹,所以我知道他们被复制。

  • 他们的时间戳对应于我上次构建项目时,所以我知道他们是最新的

  • 项目属性>调试>启动外部程序:已经自动设置为 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe ,而命令行参数自动设置为 / rootsuffix Exp

  • Visual Studio日志(使用 / log 选项)有两个与我的扩展名相关的条目:成功加载扩展名... 扩展名已启用...

  • 我的DLL不会显示在调试Visual Studio的模块选项卡(所有加载的DLL的列表)中,而某些(不是全部)其他扩展名 do 出现

  • 在笔记型电脑和台式电脑上,Visual Studio 2012或2010中没有加载。 li>


我曾尝试过:




  • 设置< IncludeAssemblyInVSIXContainer> true .csproj 文件中,这个建议,但没有任何区别。

  • 我不能将< MefComponent> |%CurrentProject%|< / MefComponent> 添加到 source.extension.vsixmanifest 文件中对于以前版本的Visual Studio(1.0。),使用与VSIX项目不同的格式(2.0) )

  • 此建议(设置 IncludeAssemblyInVSIXContainer 和我的 .csproj 中的朋友到 true ),但没有什么区别。我的断点仍然显示警告,而不是被击中。

  • 使用开始菜单中的重置Visual Studio 2012实验实例快捷方式重置VS实验实例,根据此建议。这没有什么区别。



至少要确保我的VSIX MEF扩展名已经加载,作品?如果可能,我如何通过断点工作和调试来实现?

解决方案

编辑: / strong>问题是您将 ContentTypeDefinition 未正确导出为 ClassificationTypeDefinition 。您应该使用以下代码:

  [导出] //<  - 不要在此处指定类型
[Name(ContentType)]
[BaseDefinition(code)]
内部静态ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;






这是我现在的两个猜测:


  1. 尝试从您的vsixmanifest中删除以下行。我假设您的项目中没有一个类可扩展 ,在这种情况下,由于以下资产行(您的扩展名实际上不提供此资产),Visual Studio可能会拒绝加载您的软件包。

     <资产类型=Microsoft.VisualStudio.VsPackaged:Source =Projectd:ProjectName =%CurrentProject%Path =|% CurrentProject%; PkgdefProjectOutputGroup | /> 


  2. 如果失败,请尝试将当前的source.extension.vsixmanifest替换为一个写入旧模式(1.0版)。我知道这个表单仍然在Visual Studio 2012中工作,因为所有〜20个扩展程序(使用> 10个公开发行版)都使用旧的模式。



I created a new VSIX extension project in Visual Studio 2012, and wrote a MEF classifier (as a test) that should simply highlight all text in a .mylang file. Here are the relevant parts of my .NET 4.5 code:

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.

These are the relevant parts from my source.extension.vsixmanifest file. Based on suggestions and similar files I found across the web, I added the dependency on MPF and the two 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>

I also tried a version 1.0 manifest:

<?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>


When I run it, it starts an experimental instance of Visual Studio 2012, and the Extensions and Updates window shows that my extension is active. However, it does not do anything when I load or create a .mylang file. Any exceptions I throw (as a test) from my extension are never thrown. Breakpoints are never hit, and get an exclamation mark with the following warning:

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

It feels as if my extension is never really loaded at all. My problem is similar to this problem and this problem, but I'm using Visual Studio 2012 which uses a new VSIX manifest format.

What I know:

  • I can find my DLL and VSIX file in the %localappdata%\Microsoft\VisualStudio\11.0Exp\Extensions\MyLang\VSIXProject1\1.0 folder, so I know they are copied.
  • Their timestamp corresponds to when I last built the project, so I know they are up-to-date.
  • Project Properties > Debug > Start external program: is already automatically set to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe, and the Command line arguments were automatically set to /rootsuffix Exp.
  • The Visual Studio log (created with the /log option) has two entries related to my extension: Successfully loaded extension... and Extension is enabled....
  • My DLL does not appear on the Modules tab (list of all loaded DLLs) of the debugging Visual Studio, while some (not all) other extensions do appear.
  • It doesn't get loaded in Visual Studio 2012 or 2010 both on my laptop and my desktop PC.

What I've tried:

  • Set <IncludeAssemblyInVSIXContainer> to true in the .csproj file, per this suggestion, but it did not make any difference.
  • I can't add the line <MefComponent>|%CurrentProject%|</MefComponent> to the source.extension.vsixmanifest file as it uses a different format (2.0) than VSIX projects for previous versions of Visual Studio (1.0).
  • This suggestion (setting IncludeAssemblyInVSIXContainer and friends in my .csproj to true) but it does not make a difference. And my breakpoints are still showing the warning and not being hit.
  • Reset the VS Experimental instance using the Reset the Visual Studio 2012 Experimental Instance shortcut in the Start Menu, as per this suggestion. It didn't make a difference.

How can I at the very least be sure my VSIX MEF extension is loaded and works? And if possible, how can I make by breakpoint work and debug it?

解决方案

Edit: The problem is you've improperly exported your ContentTypeDefinition as a ClassificationTypeDefinition. You should use the following instead:

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


Here's my two guesses right now:

  1. Try removing the following line from your vsixmanifest. I assume you do not have a class in your project that extends Package, in which case Visual Studio might be refusing to load your package due to the following Asset line (your extension does not actually provide this asset).

    <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
    

  2. If that fails, try replacing your current source.extension.vsixmanifest with one written to the old schema (version 1.0). I know this form still works in Visual Studio 2012 because all ~20 extensions I work on (with >10 public releases) use the old schema.

这篇关于VS2012的VSIX扩展在调试时不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆