Issue with visual studio template & directory creation -
i'm trying make visual studio (2010) template (multi-project). seems good, except projects being created in sub-directory of solution. not behavior i'm looking for.
the zip file contains:
folder1 +-- project1 +-- project1.vstemplate +-- project2 +-- project2.vstemplate myapplication.vstemplate
here's root template:
<vstemplate version="3.0.0" type="projectgroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <templatedata> <name>my application</name> <description></description> <icon>icon.ico</icon> <projecttype>csharp</projecttype> <requiredframeworkversion>4.0</requiredframeworkversion> <defaultname>myapplication</defaultname> <createnewfolder>false</createnewfolder> </templatedata> <templatecontent> <projectcollection> <solutionfolder name="folder1"> <projecttemplatelink projectname="$safeprojectname$.project1">folder1\project1\project1.vstemplate</projecttemplatelink> <projecttemplatelink projectname="$safeprojectname$.project2">folder2\project2\project2.vstemplate</projecttemplatelink> </solutionfolder> </projectcollection> </templatecontent> </vstemplate>
and, when creating solution using template, end directories this:
projects +-- myapplication1 +-- myapplication1 // i'd have not directory +-- folder1 +-- project1 +-- project2 solution file
any help?
edit:
it seems modifying <createnewfolder>false</createnewfolder>
, either true or false, doesn't change anything.
to create solution @ root level (not nest them in subfolder) must create 2 templates: 1) projectgroup stub template wizard inside create new project @ end 2) project template
use following approach that
1. add template this
<vstemplate version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" type="projectgroup"> <templatedata> <name>x application</name> <description>x shell.</description> <projecttype>csharp</projecttype> <icon>__templateicon.ico</icon> </templatedata> <templatecontent> </templatecontent> <wizardextension> <assembly>xwizard, version=1.0.0.0, culture=neutral</assembly> <fullclassname>xwizard.fixrootfolderwizard</fullclassname> </wizardextension> </vstemplate>
2. add code wizard
// creates new project @ root level instead of subfolder. public class fixrootfolderwizard : iwizard { #region fields private string defaultdestinationfolder_; private string templatepath_; private string desirednamespace_; #endregion #region public methods ... public void runfinished() { addxproject( defaultdestinationfolder_, templatepath_, desirednamespace_); } public void runstarted(object automationobject, dictionary<string, string> replacementsdictionary, wizardrunkind runkind, object[] customparams) { defaultdestinationfolder_ = replacementsdictionary["$destinationdirectory$"]; templatepath_ = path.combine( path.getdirectoryname((string)customparams[0]), @"template\xsubprojecttemplatewizard.vstemplate"); desirednamespace_ = replacementsdictionary["$safeprojectname$"]; string error; if (!validatenamespace(desirednamespace_, out error)) { controller_.showerror("entered namespace invalid: {0}", error); controller_.cancelwizard(); } } public bool shouldaddprojectitem(string filepath) { return true; } #endregion } public void addxproject( string defaultdestinationfolder, string templatepath, string desirednamespace) { var dte2 = (dte) system.runtime.interopservices.marshal.getactiveobject("visualstudio.dte.10.0"); var solution = (envdte100.solution4) dte2.solution; string destinationpath = path.combine( path.getdirectoryname(defaultdestinationfolder), "x"); solution.addfromtemplate( templatepath, destinationpath, desirednamespace, false); directory.delete(defaultdestinationfolder); }
Comments
Post a Comment