【发布时间】:2013-05-07 14:46:19
【问题描述】:
我在 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 { }
这些是我的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 的实验实例,Extensions and Updates 窗口显示我的扩展处于活动状态。但是,当我加载或创建 .mylang 文件时,它不会做任何事情。我从扩展中抛出(作为测试)的任何异常都不会被抛出。断点永远不会被命中,并会得到一个感叹号,并带有以下警告:
当前不会命中断点。没有为此文档加载任何符号。
感觉好像我的扩展程序根本没有真正加载。我的问题类似于this problem 和this problem,但我使用的是使用新的 VSIX 清单格式的 Visual Studio 2012。
我知道的:
- 我可以在
%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 的 Modules 选项卡(所有加载的 DLL 的列表)上,而一些(不是全部)其他扩展 出现。
- 我的笔记本电脑和台式电脑上的 Visual Studio 2012 或 2010 都没有加载它。
我尝试过的:
- 根据this suggestion,在.csproj 文件中将
<IncludeAssemblyInVSIXContainer>设置为true,但没有任何区别。 - 我不能将行
<MefComponent>|%CurrentProject%|</MefComponent>添加到 source.extension.vsixmanifest 文件中,因为它使用的格式 (2.0) 与以前版本的 VSIX 项目不同Visual Studio (1.0)。 -
This suggestion(将我的 .csproj 中的
IncludeAssemblyInVSIXContainer和朋友设置为true),但这并没有什么不同。而且我的断点仍然显示警告并且没有被命中。 - 按照this suggestion,使用开始菜单中的重置 Visual Studio 2012 实验性实例 快捷方式重置 VS 实验性实例。没有什么不同。
如何至少确保我的 VSIX MEF 扩展已加载并正常工作?如果可能的话,我怎样才能通过断点工作并调试它?
【问题讨论】:
-
source.extension.vsixmanifest 行应如下所示(与您的不同之处在于包含
%字符):<MefComponent>|%CurrentProject%|</MefComponent> -
@280Z28 由于我的 source.extension.vsixmanifest 格式完全不同(它是 2.0 版,而不是 1.0 版),我认为
<MefComponent>|%CurrentProject%|</MefComponent>不应该在其中。 -
下面的呢?
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" /> -
@280Z28 我寄予厚望,但是唉...没有改变任何事情(删除 obj 和 bin 文件夹后,清理并进行重建)。我在帖子中添加了完整的 vsixmanifest。
标签: c# debugging visual-studio-2012 vsix