Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 将CustomParameter与Visual Studio多项目模板一起使用_Visual Studio 2010_Visual Studio_Visual Studio Templates - Fatal编程技术网

Visual studio 2010 将CustomParameter与Visual Studio多项目模板一起使用

Visual studio 2010 将CustomParameter与Visual Studio多项目模板一起使用,visual-studio-2010,visual-studio,visual-studio-templates,Visual Studio 2010,Visual Studio,Visual Studio Templates,我希望能够为包含以下两个项目的解决方案创建一个接口(接口应包括对业务层的引用): .interface .business 通常,您可以包括以下内容: 用户在“新建项目”对话框中提供的名称 但是,正如文章中指出的, 这里的问题是,在每个子模板中,$safeprojectname$表示当前项目名称。需要有一种方法从父模板传入根$safeprojectname$ 我正试图通过使用实现这个问题中建议的解决方案,但遇到了麻烦 我的压缩模板目录如下所示: MultiTemplate.vstempla

我希望能够为包含以下两个项目的解决方案创建一个接口(接口应包括对业务层的引用):

  • .interface
  • .business
通常,您可以包括以下内容:

用户在“新建项目”对话框中提供的名称

但是,正如文章中指出的,

这里的问题是,在每个子模板中,$safeprojectname$表示当前项目名称。需要有一种方法从父模板传入根$safeprojectname$

我正试图通过使用实现这个问题中建议的解决方案,但遇到了麻烦

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

  • MultiTemplate.vstemplate
  • 接口
    • InterfaceTemplate.vstemplate
    • MyTemplate.Interface.csproj
  • 生意
    • BusinessTemplate.vstemplate
    • MyTemplate.Business.csproj
您可以下载,但这里有一些精选片段

多模板.vstemplate


Interface\InterfaceTemplate.vstemplate
Business\BusinessTemplate.vstemplate
接口\InterfaceTemplate.vstemplate


MyTemplate.Interface.csproj


{E551F75-5B9C-4816-B991-E09225661CF4}
MyTemplate.业务
问题 创建新项目时,字符串的
$SolutionName$
部分不会被替换。相反,它只是保持不变

Q:如何将此信息从多项目模板正确传递到每个子模板


如果你能找到替换标记值的方法,就可以获得额外的积分,因为替换标记似乎不起作用。

完全公开:我是下面提到的项目的创建者

我解决了多项目模板中项目模板之间共享信息的问题,创建了一个名为。它通过在ALL解决方案级别参数前面加上单词global并将其添加到子参数中,使解决方案模板级别的信息可供也运行向导的子模板使用

如果您与上述模板一起使用,并且用户输入了“测试项目”,则以下内容是正确的:

  • InterfaceTemplate.vstemplate无法访问
    • $safeprojectname$
      =Test\u Project.Interface
    • $globalsafeprojectname$
      =测试项目
  • BusinessTemplate.vstemplate无法访问
    • $safeprojectname$
      =Test\u Project.Business
    • $globalsafeprojectname$
      =测试项目

以上是安全项目名称的示例,但解决方案模板中的所有参数都会传递给子模板。有关详细信息,请参见。

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

CopyParameters
属性将允许子级访问父模板的所有变量,其前缀为
ext\uu

你甚至不需要自定义参数。将您的ProjectTemplateLink更改为:


Interface\InterfaceTemplate.vstemplate
然后您可以在child
.csproj
中实现您的目标,如下所示:


{E551F75-5B9C-4816-B991-E09225661CF4}
MyTemplate.业务

从我的角度来看(鉴于我的项目所描述的方法是功能性的),VS不替换令牌的唯一原因可能是项目类型。可悲的是,我现在几乎没有时间来测试这一点,但是我建议你用一个Web项目类型制作一个类似的模板,并检查标记是否只被替换为Web项目类型……你会考虑改变你所接受的答案吗?原始答案仅托管在Codeplex上,Codeplex将于2017年晚些时候关闭。作为当前标记答案的作者,我支持将其更改为@friggle的答案。使用新的内置功能是一个更好的解决方案。@TroyPalacino,是的,很好。谢谢你的轻推。获得一些奖励积分作为接受安慰奖您如何使用模板重命名文件?是否可以允许cusotm参数值传递给子模板?@AlexGordon I刚刚使用了自定义参数和$ext_mycustomparam$。