问题
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>
回答1:
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.
回答2:
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
回答3:
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/
来源:https://stackoverflow.com/questions/2023887/visual-studio-templates-adding-additional-pre-existing-projects