Visual Studio 模板 - 添加其他预先存在的项目
我正在开发一个 Visual Studio 模板,其中生成的项目依赖于许多引用,这些引用恰好是源代码控制下的其他项目。
问题是如何在我的 ProjectGroup 模板中进行设置?例如,如果我在“C:\Stuff\MyUtilityProject\Utility.csproj”处已有一个项目,其中包含一个文件 (Tools.cs),我想将其添加到我的模板中,我将如何处理?
这是我的 vstempalte 的样子。仅供参考 - 我对 ProjectTemplateLink 或创建解决方案文件夹没有任何问题,只需将预先存在的 Utility.csproj 添加到我的新解决方案中即可:
提前致谢!
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
<TemplateData>
<Name>MySampleSolution</Name>
<Description>My Test Project</Description>
<ProjectType>CSharp</ProjectType>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<SolutionFolder Name="Content">
<Project File="C:\Stuff\MyUtilityProject\Utility.csproj">
<ProjectItem>Tools.cs</ProjectItem>
</Project>
</SolutionFolder>
<ProjectTemplateLink ProjectName="MyWorkingTemplate">
MyWorkingTemplate\MyTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
I'm working on a Visual Studio template where the generated project relies on a number of references, which happen to be other projects under source control.
The question is how do I set this up in my ProjectGroup template? For example, if I have an already existing project at "C:\Stuff\MyUtilityProject\Utility.csproj" with a single file (Tools.cs) that I want to add to my template, how would I go about this?
Here's what my vstempalte looks like. FYI - I am having no issues with the ProjectTemplateLink or creation of the Solution folder, just in adding the pre-existing Utility.csproj to my new solution:
Thanks in advance!
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
<TemplateData>
<Name>MySampleSolution</Name>
<Description>My Test Project</Description>
<ProjectType>CSharp</ProjectType>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<SolutionFolder Name="Content">
<Project File="C:\Stuff\MyUtilityProject\Utility.csproj">
<ProjectItem>Tools.cs</ProjectItem>
</Project>
</SolutionFolder>
<ProjectTemplateLink ProjectName="MyWorkingTemplate">
MyWorkingTemplate\MyTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 Visual Studio 2010 (Ultimate) 中知道的唯一解决方法是从模板创建项目/解决方案,添加 *.cs 文件您需要,然后使用模板导出向导再次导出解决方案。
对于您拥有的库,您可以创建一个项目模板,而不是项目/解决方案模板 - 这允许使用add -> 添加它。从 Visual Studio 解决方案资源管理器的上下文菜单中添加新项目。
要创建项目模板,请打开您的解决方案,然后使用文件 ->导出模板...,并在向导对话框打开后选择项目模板作为导出类型。
确保在向导中选中“导入”复选框,否则创建后不会自动安装。
The only workaround I know in Visual Studio 2010 (Ultimate) is to create a project/solution from your template, add the *.cs files you need and then export the solution again using the template export wizard.
For the library you have you can create an item template rather than a project/solution template - this allows to add it using add -> new item from the context menu in the solution explorer of Visual Studio.
To create an item template, open your solution, then use File -> Export template... and select item template as export type once the wizard dialog opens.
Ensure that you have the "import" checkbox checked on the wizard, otherwise it will not be automatically installed after you've created it.
您可以托管您自己的 NuGet feed(或者使用 NuGet 功能 ="http://jetbrains.com/teamcity" rel="nofollow">TeamCity 或私人 MyGet然后你只需要将你的实用程序项目打包为NuGet 包 并将其添加到项目模板中,如下所述:http://docs.nuget.org/docs/reference/packages-in-visual-studio-templates
You could host your own NuGet feed (or use the NuGet capabilities of TeamCity or a private MyGet feed. Then you would just need to package your utility project as a NuGet package and add it to your project template as described here: http://docs.nuget.org/docs/reference/packages-in-visual-studio-templates
这是您正在寻找的内容:
Visual Studio - 以编程方式配置源解决方案control
编辑:
我一直在环顾四周,看到了这个相当有趣的项目,它似乎导出解决方案而不是项目,这可能是也可能不是更好的主意。我特别喜欢最后的部分,它说它将去除源代码控制,这样你就可以得到一个干净的项目。我知道这不是您想要的确切答案,但值得一看;)
http://flux88.com/blog/exporting-visual-studio-solutions-with-solutionfactory/
Is this what you are looking for:
Visual Studio - Programmatically configure solution for source control
EDIT:
I have been looking around an seen this rather interesting project, it seems to export solutions rather than projects which may or may not be a better idea. I particularly like the part at the end that says it will strip out source control so you get a clean project. I know this is not the exact answer you would like but it is worth a look ;)
http://flux88.com/blog/exporting-visual-studio-solutions-with-solutionfactory/