Dan*_*ker 10 c# debugging vsix visual-studio-2012
我在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 { }
Run Code Online (Sandbox Code Playgroud)
这些是我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>
Run Code Online (Sandbox Code Playgroud)
我还尝试了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>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它启动Visual Studio 2012的实验性实例," 扩展和更新"窗口显示我的扩展是活动的.但是,当我加载或创建.mylang文件时,它不会执行任何操作.我从我的扩展中抛出(作为测试)的任何异常都不会被抛出.断点永远不会被击中,并获得带有以下警告的感叹号:
断点当前不会被击中.没有为此文档加载任何符号.
感觉好像我的扩展从未真正加载过.我的问题类似于这个问题和这个问题,但我使用的是使用新的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./log选项创建)有两个与我的扩展名相关的条目:Successfully loaded extension...和Extension is enabled....我尝试过的:
<IncludeAssemblyInVSIXContainer>于true在.csproj的文件,每本的建议,但它并没有任何区别.<MefComponent>|%CurrentProject%|</MefComponent>到source.extension.vsixmanifest文件中,因为它使用的格式(2.0)与以前版本的Visual Studio(1.0)的VSIX项目不同.IncludeAssemblyInVSIXContainer和朋友在我的.csproj到true),但它不会有所作为.我的断点仍在显示警告而未被击中.我怎么能至少确定我的VSIX MEF扩展已加载并且有效?如果可能的话,我如何通过断点工作并调试它?
编辑:问题是你不正确地导出你ContentTypeDefinition的ClassificationTypeDefinition.您应该使用以下代码:
[Export] // <-- don't specify the type here
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;
Run Code Online (Sandbox Code Playgroud)
这是我现在的两个猜测:
尝试从vsixmanifest中删除以下行.我假设您的项目中没有扩展的类Package,在这种情况下,由于以下资产行,Visual Studio可能拒绝加载您的包(您的扩展实际上并未提供此资产).
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
Run Code Online (Sandbox Code Playgroud)如果失败,请尝试将当前的source.extension.vsixmanifest替换为写入旧架构(版本1.0)的源码.我知道这个表单在Visual Studio 2012中仍然有效,因为我所使用的所有~20个扩展(具有> 10个公共版本)都使用旧模式.
| 归档时间: |
|
| 查看次数: |
4191 次 |
| 最近记录: |