6

I've created a custom language package, which extends ProjectPackage. I can create the new project correctly. I would like to be able to add new source files to the project by using the Add->New Item... (Ctrl+Shift+A) menu item. However, when I click this at the moment the list of available templates is empty. I would like to add my own custom template to the menu of available templates for this project type. Is there some documentation for accomplishing this? The only mentions I have seen have been registry hacks, but there has to be a way to do the programmatically I would think.

Is there a particular method I can override to populate the list? Do I really need to make a template, or can I just show the 'template name', 'icon' and provide the correct file extension (the files should be empty when created, so I think a template is largely wasted on what I want to do).

Here's the path I've been traveling down thus far. I figured I could set my project type and GUID in my custom .vproj file (.vproj is the file extension that my custom project is registered under). I thought I could quickly create a item template with the same ProjectType as my .vproj file.

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <Icon>VerilogSource.ico</Icon>
    <DefaultName>module.v</DefaultName>
    <Name>Basic Verilog Module</Name>
    <Description>
      A basic Verilog module for quickly adding new files to the project.
    </Description>
    <ProjectType>VerilogProject</ProjectType>
  </TemplateData>
  <TemplateContent>
    <ProjectItem TargetFileName="$fileinputname$.v"
        ReplaceParameters="true">module.v</ProjectItem>
  </TemplateContent>
</VSTemplate>

Alas, this template does not show up at all, even though I've included it in VSIX and copied it to the output directory. If I put this template in the same folder as my .vproj, it will appear as a template for creating a new project (wrong!) and still won't appear in my new items list. This could all derive from the fact that I do not use a VSTemplate for creating my project. Instead I use [ProvideProjectFactoryAttribute] to let VS2010 know where my vproj file is, and it will use the vproj file (which I guess you could call a template, but it isn't a VSTemplate, it is a Project) to base the new project off of.

This is where I am at so far, and I'm continuing to try new things. I'm hoping someone might have the answer I am looking for. Thanks,

Giawa

4

2 に答える 2

4

多くの読書と作業の後、これが私の答えです:

プロジェクトとアイテムに vstemplate ファイルを使用し、それらを vstemplate としてコンパイルします ( Microsoft ウォークスルーが示唆していることに反して、出力にコピーしたり、VSIX に含めたりしないでください)。コンパイラは、各アイテムとプロジェクト テンプレートを独自の zip ファイルにパッケージ化します。ここで、これらのファイルの場所を vsixmanifest に伝える必要があります。プロジェクトとアイテムの既定のディレクトリは、それぞれ ProjectTemplates と ItemTemplates です。次のように vsixmanifest に追加します。

  <Content>
    <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
    <ProjectTemplate>ProjectTemplates</ProjectTemplate>
    <ItemTemplate>ItemTemplates</ItemTemplate>
  </Content>

ここで、vsix パッケージが組み込まれている .csproj ファイルにいくつかのプロパティを追加する必要もあります。これらのプロパティは、おそらく複雑な方法で追加できますが、最も簡単な方法は、.csproj ファイルに直接ドロップすることです。

  <PropertyGroup>
    <GetVsixSourceItemsDependsOn>$(GetVsixSourceItemsDependsOn);GetVsixTemplateItems</GetVsixSourceItemsDependsOn>
  </PropertyGroup>
  <Target Name="GetVsixTemplateItems" DependsOnTargets="ZipProjects;ZipItems">
    <ItemGroup>
      <VSIXSourceItem Include="@(IntermediateZipItem)">
        <VSIXSubPath>ItemTemplates\%(IntermediateZipItem.Language)\%(IntermediateZipItem.OutputSubPath)\%(IntermediateZipItem.Culture)</VSIXSubPath>
      </VSIXSourceItem>
      <VSIXSourceItem Include="@(IntermediateZipProject)">
        <VSIXSubPath>ProjectTemplates\%(IntermediateZipProject.Language)\%(IntermediateZipProject.OutputSubPath)\%(IntermediateZipProject.Culture)</VSIXSubPath>
      </VSIXSourceItem>
    </ItemGroup>
  </Target>

これで zip ファイルがプロジェクトに取り込まれ、運が良ければ、プロジェクトとアイテムが正しくリンクされた状態になります。

幸いなことに、アイテム/プロジェクトのテンプレートについては、かなりの数のドキュメントが公開されています。それが正しい道だと気付くのに少し時間がかかりました。幸運を、

ギアワ

于 2011-07-27T06:55:00.963 に答える
0

これらの手順はすべて、Visual Studio内で自動的に実行できます。

最初に別のプロジェクトで項目テンプレートを作成します ( で作成できますFile > Export template)。ファイルを編集して、このテンプレートをカスタマイズでき.vstemplateます。

ファイルを取得したら、それをメインソリューション.zipにドラッグ アンド ドロップし、次の操作を行います。VSPackage

  1. ファイルをクリックし.vsixmanifestます。
  2. をクリックしAssets > Newます。
  3. (アイテム テンプレート) に設定Typeします。Microsoft.VisualStudio.ItemTemplate
  4. を に設定SourceFile on filesystemます。
  5. Pathをアイテム テンプレート.zipファイルに設定します。
  6. ソリューションを再構築します。

注: Visual Studio 2013を使用していました。

于 2015-06-25T21:43:39.037 に答える