我在 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 { }
这是完整的代码 http://pastebin.com/kpY4fCaU.
这些是我的相关部分source.extension.vsixmanifest
文件。根据我在网络上找到的建议和类似文件,我添加了对 MPF 和这两个资产的依赖项。
<?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 版本的清单:
<?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 文件时,它不会执行任何操作。我从扩展中抛出的任何异常(作为测试)都不会被抛出。断点永远不会被击中,并且会出现感叹号并显示以下警告:
当前不会命中断点。尚未为此文档加载任何符号。
感觉好像我的扩展从未真正加载过。我的问题类似于这个问题 https://stackoverflow.com/q/1778797/146622 and 这个问题 https://stackoverflow.com/q/7767249/146622,但我使用的是 Visual Studio 2012,它使用新的 VSIX 清单格式。
我知道的:
- 我可以在以下位置找到我的 DLL 和 VSIX 文件
%localappdata%\Microsoft\VisualStudio\11.0Exp\Extensions\MyLang\VSIXProject1\1.0
文件夹,所以我知道它们已被复制。
- 它们的时间戳对应于我上次构建项目的时间,所以我知道它们是最新的。
-
项目属性>调试>启动外部程序:已经自动设置为
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe
,以及命令行参数被自动设置为/rootsuffix Exp
.
- Visual Studio 日志(使用
/log
选项)有两个与我的扩展相关的条目:Successfully loaded extension...
and Extension is enabled...
.
- 我的 DLL 确实如此not出现在Modules调试 Visual Studio 的选项卡(所有加载的 DLL 的列表),而一些(不是全部)其他扩展do appear.
- 它无法在我的笔记本电脑和台式电脑上的 Visual Studio 2012 或 2010 中加载。
我尝试过的:
- Set
<IncludeAssemblyInVSIXContainer>
to true
in the .csproj文件,每这个建议 https://stackoverflow.com/a/1787089/146622,但这没有任何区别。
- I can't添加行
<MefComponent>|%CurrentProject%|</MefComponent>
to the 源.扩展.vsixmanifest文件,因为它使用与早期版本的 Visual Studio (1.0) 的 VSIX 项目不同的格式 (2.0)。
-
这个建议 https://stackoverflow.com/a/7774371/146622(环境
IncludeAssemblyInVSIXContainer
和我的朋友们.csproj to true
)但这没有什么区别。我的断点仍然显示警告并且没有被击中。
- 使用以下命令重置 VS 实验实例重置 Visual Studio 2012 实验实例开始菜单中的快捷方式,按照这个建议 https://stackoverflow.com/a/10191878/146622。这没有什么区别。
我至少如何确保我的 VSIX MEF 扩展已加载并正常工作?如果可能的话,我怎样才能通过断点工作并调试它?