为 Visual Studio 2008 创建一个具有文件依赖性的项目模板,是否可能?
我有一个模板,可将新条目添加到 Visual Studio 解决方案资源管理器中项目的“添加->新项目”右键菜单中。
我已经构建了模板,将其放入文档文件夹下的 ItemTemplates 目录中,并且它可以工作,因为我可以通过模板向项目添加新项目。
但是,该模板由 3 个文件组成:
<filename>.controller
<filename>.Designer.cs
<filename>.cs
这些文件被添加到同一级别的项目中,但我希望拥有与向项目添加表单时获得的相同类型的层次结构,其中 .Designer.cs 文件作为子节点放置在 .cs 文件下。
基本上,这就是该项目的样子:
TestProject
+- Properties
+- References
+- App.config
+- Program.cs
+- MyTestController.controller
+- MyTestController.Designer.cs
+- MyTestController.cs
而我希望它看起来像这样:
TestProject
+- Properties
+- References
+- App.config
+- Program.cs
+- MyTestController.controller
+- MyTestController.Designer.cs
+- MyTestController.cs
这可能吗?如果是这样,我应该在 .vstemplate 文件中更改什么才能获得此行为?
这是我添加到模板 zip 文件中的 .vstemplate 文件:
<VSTemplate Version="2.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>LVK.NET New Controller</Name>
<Description>Adds an business logic controller class to the project.</Description>
<Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4522" />
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<DefaultName>Controller.controller</DefaultName>
</TemplateData>
<TemplateContent>
<References>
<Reference>
<Assembly>System</Assembly>
</Reference>
<Reference>
<Assembly>System.Data</Assembly>
</Reference>
<Reference>
<Assembly>System.Xml</Assembly>:\
</Reference>
<Reference>
<Assembly>LVK.Core</Assembly>
</Reference>
<Reference>
<Assembly>LVK.BusinessLogic</Assembly>
</Reference>
</References>
<ProjectItem ReplaceParameters="true">Controller.controller</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.Designer.cs">Controller.Designer.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.cs">Controller.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
I have a template that adds a new entry to the "Add->New item" right-click menu on a project in the solution explorer in Visual Studio.
I have already built the template, put it into my ItemTemplates directory beneath my documents folder, and it works, in the sense that I can add new items to the project through the template.
However, the template consists of 3 files:
<filename>.controller
<filename>.Designer.cs
<filename>.cs
These are added to the project at the same level, but I'd like to have the same kind of hierarchy you get when you add a form to the project, where the .Designer.cs file is placed as a sub-node beneath the .cs file.
Basically, this is what the project looks like:
TestProject
+- Properties
+- References
+- App.config
+- Program.cs
+- MyTestController.controller
+- MyTestController.Designer.cs
+- MyTestController.cs
whereas I want it to look like this:
TestProject
+- Properties
+- References
+- App.config
+- Program.cs
+- MyTestController.controller
+- MyTestController.Designer.cs
+- MyTestController.cs
is this possible? If so, what do I change in my .vstemplate file to get this behaviour?
Here's the .vstemplate file I've added to the template zip file:
<VSTemplate Version="2.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>LVK.NET New Controller</Name>
<Description>Adds an business logic controller class to the project.</Description>
<Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4522" />
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<DefaultName>Controller.controller</DefaultName>
</TemplateData>
<TemplateContent>
<References>
<Reference>
<Assembly>System</Assembly>
</Reference>
<Reference>
<Assembly>System.Data</Assembly>
</Reference>
<Reference>
<Assembly>System.Xml</Assembly>:\
</Reference>
<Reference>
<Assembly>LVK.Core</Assembly>
</Reference>
<Reference>
<Assembly>LVK.BusinessLogic</Assembly>
</Reference>
</References>
<ProjectItem ReplaceParameters="true">Controller.controller</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.Designer.cs">Controller.Designer.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.cs">Controller.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在项目文件(例如 .csproj)中指定您的“层次结构”:
并将项目文件添加到您的 .vstemplate
完成;-)
Specify your "hierachy" in the projectfile (e.g. .csproj):
and add the project file to your .vstemplate
Done ;-)
依赖文件需要引用“父”文件,如下所示:
The dependent files need to reference the "parent" file as such: