Using CustomParameter with Visual Studio Multi-Project Template

拥有回忆 提交于 2019-11-27 20:03:52
friggle

Visual Studio 2013 Update 2 finally added a built-in way to do this with ProjectTemplateLink

The CopyParameters attribute will enable child access to all the variables of the parent template, with the prefix of ext_.

You don't even need CustomParameters for this. Change your ProjectTemplateLink to this:

<ProjectTemplateLink ProjectName="$safeprojectname$.Interface" CopyParameters="true">
  Interface\InterfaceTemplate.vstemplate
</ProjectTemplateLink>

And then you can achieve your goal in the child .csproj like so:

<ItemGroup>
  <ProjectReference Include="..\$ext_safeprojectname$.Business\$ext_safeprojectname$.Business.csproj">
    <Project>{E5511F75-5B9C-4816-B991-E09225661CF4}</Project>
    <Name>MyTemplate.Business</Name>
  </ProjectReference>
</ItemGroup>
Troy Palacino

Full Disclosure: I am the creator of the below mentioned project.

I solved the issue of sharing information between project templates in a multi-project template be creating an IWizard implementation called GlobalParams. It makes the information from the solution template level available to the child templates that also run the wizard by prefixing ALL solution level parameters with the word global and adding it to the child parameters.

If you used GlobalParams with the above template and the user entered "Test Project", the following would be true:

  • InterfaceTemplate.vstemplate could access
    • $safeprojectname$ = Test_Project.Interface
    • $globalsafeprojectname$ = Test_Project
  • BusinessTemplate.vstemplate could access
    • $safeprojectname$ = Test_Project.Business
    • $globalsafeprojectname$ = Test_Project

The above is an example of the safe project name but all parameters from the solution template are passed to child template See the GlobalParams Documentation for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!