I have a solution that contains several projects, lets call them ProjectA and ProjectB. I need ProjectA to have a reference to ProjectB, however when I "Export Template" I can't seem to keep the reference. What I am trying to do is to have it create the reference for me when I create a new project and then automatically name it to what I entered.
This is slightly out of scope for pure Visual Studio templates.
Visual Studio templates supports replacements parameters for templates, so what you could do is:
ProjectA.zip
template file you will find ProjectA.csproj
, which is the template for the projectProjectA.csproj
you will find an <ItemGroup>
containing <Reference>
entries<Reference Include="ProjectB">
When you create a project from your ProjectB-template, it's name will be user-specified, so you want to replace ProjectB
with a replacement parameter like $Foo$
.
This is where it gets out of scope for pure templates: How do you tell visual studio to replace $Foo$
? And what would the replacement be?
Your only choice here it to use a custom wizard, which either looks for the ProjectB-type project or asks the user for it.
Here's an outline for how to get the template and custom wizard to get along:
[ProvideBindingPath]
attribute to your package. This is required to get the custom wizard registered (otherwise you would need to install it to the GAC, so VS can find it)Microsoft.VisualStudio.TemplateWizard.IWizard
In the .vstemplate file of your template, add the following snippet below the <TemplateContent>
block:
<WizardExtension>
<Assembly>Your.Packages.Assembly</Assembly>
<FullClassName>Your.Wizard</FullClassName>
</WizardExtension>
That will bring up your wizard when the project is created. You could, in the RunStarted
method bring up a dialog which asks for the reference or you could use the automationObject
parameter (which actually is a EnvDTE.DTE
instance) to try and find the ProjectB project and supply it's name in the replacementsDictionary
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With