gpt4 book ai didi

visual-studio-2010 - 将 CustomParameter 与 Visual Studio 多项目模板结合使用

转载 作者:行者123 更新时间:2023-12-02 03:00:23 25 4
gpt4 key购买 nike

我希望能够创建一个Multi-Project Template对于包含以下两个项目的解决方案(其中接口(interface)应包含对业务层的引用):

  • <proj_name>.interface
  • <proj_name>.business .

通常,您可以包含 $safeprojectname$ ,其中有:

The name provided by the user in the New Project dialog box

但是,正如文章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.

我正在尝试实现这个SO问题VS 2010 Multi-Project Template: Inter-Project References中建议的解决方案,通过使用 CustomParameters ,但我遇到了麻烦。

我的压缩模板目录如下所示:

  • MultiTemplate.vstemplate
  • 界面
    • InterfaceTemplate.vstemplate
    • MyTemplate.Interface.csproj
  • 业务
    • BusinessTemplate.vstemplate
    • MyTemplate.Business.csproj

您可以下载Entire Directory ,但这里有一些精选片段

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>,则可获得奖励积分标记值,因为 token 替换似乎不起作用。

最佳答案

Visual Studio 2013 Update 2 最终添加了一种内置方法来执行此操作 ProjectTemplateLink

CopyParameters 属性将使子级能够访问父模板的所有变量,前缀为 ext_

您甚至不需要 CustomParameters。将您的 ProjectTemplateLink 更改为:

<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>

关于visual-studio-2010 - 将 CustomParameter 与 Visual Studio 多项目模板结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19662836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com