Visual Studio 2012 で新しい VSIX 拡張プロジェクトを作成し、.mylang
ファイル内のすべてのテキストを単純に強調表示する MEF 分類子を (テストとして) 作成しました。私の.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
ファイルの関連部分です。Web で見つけた提案や同様のファイルに基づいて、MPF と 2 つのアセットへの依存関係を追加しました。
<?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 ファイルをロードまたは作成すると、何も実行されません。拡張機能から (テストとして) スローした例外はスローされません。ブレークポイントがヒットすることはなく、次の警告とともに感嘆符が表示されます。
ブレークポイントは現在ヒットしません。このドキュメントのシンボルは読み込まれていません。
私の拡張機能がまったくロードされていないように感じます。私の問題はこの問題とこの問題に似ていますが、新しい VSIX マニフェスト形式を使用する Visual Studio 2012 を使用しています。
私が知っていること:
- 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
オプションで作成) には、私の拡張機能に関連する 2 つのエントリがあります:Successfully loaded extension...
とExtension is enabled...
. - 私の DLL は、Visual Studio のデバッグの [モジュール] タブ (読み込まれたすべての DLL のリスト) に表示されませんが、一部の (すべてではない) 他の拡張機能は表示されます。
- ラップトップとデスクトップ PC の両方で、Visual Studio 2012 または 2010 に読み込まれません。
私が試したこと:
- この提案に従って、.csprojファイルに設定
<IncludeAssemblyInVSIXContainer>
しますが、違いはありませんでした。true
- 以前のバージョンの Visual Studio (1.0) の VSIX プロジェクトとは異なる形式 (2.0) を使用しているため、source.extension.vsixmanifestファイルに行を追加できません。
<MefComponent>|%CurrentProject%|</MefComponent>
- この提案( .csprojの設定
IncludeAssemblyInVSIXContainer
と友達を) にしますが、違いはありません。そして、私のブレークポイントはまだ警告を表示しており、ヒットしていません。true
- この提案に従って、[スタート] メニューの [ Visual Studio 2012 実験的インスタンスをリセット] ショートカットを使用して、VS 実験的インスタンスをリセットします。違いはありませんでした。
少なくとも、VSIX MEF 拡張機能が読み込まれて動作していることを確認するにはどうすればよいですか? 可能であれば、ブレークポイントで動作させてデバッグするにはどうすればよいですか?