0

オンライン チュートリアルに従って、Visual Studio ファイル ジェネレーター (別名カスタム ツール) を作成および登録する方法を学習しようとしました。別の Visual Studio プロジェクトで、'VsTools' (ファイル ジェネレーターのクラスの名前空間) を .txt ファイルの "カスタム ツール" として割り当てることができるため、ツールを少なくとも部分的に登録できたと思います。 .txt ファイルのプロパティ ダイアログを開き、ツールを実行すると、個別のファイルが生成されます。ただし、生成されたファイルには数値 (具体的には、カスタム ツールが適用されたファイルの行数) が表示されると思いますが、生成されたファイルにはコンテンツがまったくありません。

ファイルジェネレーターを誤って登録したり、ソースファイルの行数を取得するために使用されるカスタムロジックを誤って実装したりする方法を理解するのを手伝ってくれる人はいますか?

IVsSingleFileGenerator の実装コードは次のとおりです。

namespace VsTools
{
    [Guid("A2...")]
    public class ToolBase : IVsSingleFileGenerator
    {
        public int DefaultExtension(out string InputfileRqExtension)
        {
            InputfileRqExtension = ".txt";
            return VSConstants.S_OK;
        }

        public int Generate(
            string inputFilePath,
            string inputFileContents,
            string defaultNamespace,
            IntPtr[] outputFileContents,
            out uint outputByteCount,
            IVsGeneratorProgress generateProgress)
        {
            int lineCount = inputFileContents.Split('\n').Length;
            byte[] bytes = Encoding.UTF8.GetBytes(lineCount.ToString());
            int length = bytes.Length;
            outputFileContents[0] = Marshal.AllocCoTaskMem(length);
            Marshal.Copy(bytes, 0, outputFileContents[0], length);
            outputByteCount = (uint)length;
            return VSConstants.S_OK;
        }
    }
}

「VsTools.ToolBase」ファイル ジェネレーターの登録に使用されるレジストリ ファイル:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0_Config\CLSID\{A2..}]

"InprocServer32"="C:\\Windows\\System32\\mscoree.dll"
"ThreadingModel"="Both"
"Class"="VsTools2.ToolBase"
"Assembly"="VsTools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9b..."

"CodeBase"=file:///C:\\VsTools\\VsTools.dll

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0_Config\Generators\{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}\VsTools]

"CLSID"="{A2..}"
"GeneratesDesignTimeSource"=dword:00000001

次のコマンドが実行されました。

regasm /codebase "C:\VsTools\VsTools.dll"
gacutil /i "C:\VsTools\VsTools.dll"
4

0 に答える 0