将CustomParameter与Visual Studio多项目模板一起使用 [英] Using CustomParameter with Visual Studio Multi-Project Template
问题描述
我希望能够创建一个包含以下两个项目的解决方案的多项目模板(其中的界面应包含对业务层的引用).
-
<proj_name>.interface
-
<proj_name>.business
.
通常,您可以包含 $safeprojectname$
,其中包含:
用户在新建项目"对话框中提供的名称
但是,正如文章 VS 2010多项目模板:项目间参考,通过使用 CustomParameters
,但遇到了麻烦./p>
我的压缩模板目录如下:
- MultiTemplate.vstemplate
- 接口
- InterfaceTemplate.vstemplate
- MyTemplate.Interface.csproj
- 业务
- BusinessTemplate.vstemplate
- MyTemplate.Business.csproj
您可以下载整个目录,但这是一些精选的片段
MultiTemplate.vstemplate
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
<TemplateData><!--Removed for brevity --></TemplateData>
<TemplateContent>
<CustomParameters>
<CustomParameter Name="$SolutionName$" Value="$safeprojectname$"/>
</CustomParameters>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$.Interface">
Interface\InterfaceTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Business">
Business\BusinessTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
Interface \ InterfaceTemplate.vstemplate
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData><!--Removed for brevity --></TemplateData>
<TemplateContent>
<Project TargetFileName="MyTemplate.Interface.csproj"
File="MyTemplate.Interface.csproj"
ReplaceParameters="true">
</Project>
</TemplateContent>
</VSTemplate>
MyTemplate.Interface.csproj
<ItemGroup>
<ProjectReference Include="..\$SolutionName$.Business\$SolutionName$.Business.csproj">
<Project>{E5511F75-5B9C-4816-B991-E09225661CF4}</Project>
<Name>MyTemplate.Business</Name>
</ProjectReference>
</ItemGroup>
问题
当我创建一个新项目时,字符串的$SolutionName$
部分不会被替换.相反,它保持不变.
问:如何正确地将这些信息从多项目模板"传递给每个子模板?
如果可以弄清楚如何替换<name>
标记值,则奖励点,因为代币替换似乎不起作用.
Visual Studio 2013 Update 2最终通过 然后您可以像这样在孩子 I would like to be able to create a Multi-Project Template for a solution which contains the following two projects (where the interface should include a reference to the business layer).: Normally, you can include The name provided by the user in the New Project dialog box However, as pointed out in the article Build a multi-project visual studio template The problem here is that within each child template, $safeprojectname$ represents the current project name. There needs to be a way to pass in the root $safeprojectname$ from the parent template. I'm trying to implement the solution suggested in this SO question VS 2010 Multi-Project Template: Inter-Project References, by using My Zipped Up Template Directory looks like this: You can download the Entire Directory, but here are some select snippets MultiTemplate.vstemplate Interface\InterfaceTemplate.vstemplate MyTemplate.Interface.csproj
When I create a new project, the Q: How can I properly pass this information from the Multi-Project Template to each of the child templates? Bonus points if you can figure out how to replace the Visual Studio 2013 Update 2 finally added a built-in way to do this with The You don't even need CustomParameters for this. Change your ProjectTemplateLink to this: And then you can achieve your goal in the child
这篇关于将CustomParameter与Visual Studio多项目模板一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<ProjectTemplateLink ProjectName="$safeprojectname$.Interface" CopyParameters="true">
Interface\InterfaceTemplate.vstemplate
</ProjectTemplateLink>
.csproj
中实现您的目标:
<ItemGroup>
<ProjectReference Include="..\$ext_safeprojectname$.Business\$ext_safeprojectname$.Business.csproj">
<Project>{E5511F75-5B9C-4816-B991-E09225661CF4}</Project>
<Name>MyTemplate.Business</Name>
</ProjectReference>
</ItemGroup>
<proj_name>.interface
<proj_name>.business
.$safeprojectname$
, which has:
CustomParameters
, but am running into trouble.
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
<TemplateData><!--Removed for brevity --></TemplateData>
<TemplateContent>
<CustomParameters>
<CustomParameter Name="$SolutionName$" Value="$safeprojectname$"/>
</CustomParameters>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$.Interface">
Interface\InterfaceTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Business">
Business\BusinessTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData><!--Removed for brevity --></TemplateData>
<TemplateContent>
<Project TargetFileName="MyTemplate.Interface.csproj"
File="MyTemplate.Interface.csproj"
ReplaceParameters="true">
</Project>
</TemplateContent>
</VSTemplate>
<ItemGroup>
<ProjectReference Include="..\$SolutionName$.Business\$SolutionName$.Business.csproj">
<Project>{E5511F75-5B9C-4816-B991-E09225661CF4}</Project>
<Name>MyTemplate.Business</Name>
</ProjectReference>
</ItemGroup>
The Problem
$SolutionName$
portion of the string does not get replaced. Instead it just stays the same.<name>
tag value, as token replacements don't seem to work on it.ProjectTemplateLink
CopyParameters
attribute will enable child access to all the variables of the parent template, with the prefix of ext_
.<ProjectTemplateLink ProjectName="$safeprojectname$.Interface" CopyParameters="true">
Interface\InterfaceTemplate.vstemplate
</ProjectTemplateLink>
.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>