从“CreateProject”中调用TextTemplateAction。行动 [英] Call TextTemplateAction from within a "CreateProject" action

查看:62
本文介绍了从“CreateProject”中调用TextTemplateAction。行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个针对类似于CAB的体系结构的指导包 - 有一个shell,它可以加载模块。解决方案有一个名为Modules的文件夹,我想要一个可以在此解决方案文件夹中创建模块的配方。假设开发人员想要一个名为"ClientModule"的模块。该配方将在名为"ClientModule"的模块下创建另一个解决方案文件夹。并在此子文件夹下创建2个项目:一个名为"ClientModule"的项目。还有一个叫做"ClientModulePublisher"。为了做到这一点,我查看了SCSF指导包和"butchered"。我自己的UnfoldModuleProjectAction动作版本。此操作非常简单:创建解决方案文件夹,然后调用"AddFromTemplate";解决方案文件夹上的方法。

问题来自于在模板文件中替换$ parameters $。对于模块项目,我有一个名为Module.cs的类,其中包含一个名为$ ModuleName $的占位符。无论我如何尝试这样做,参数永远不会替换实际的ModuleName值(这是RecipeArgument)。这适用于SCSF包,但我不能让它为我的模板工作,虽然我看不出任何差异。

所以我试图将VSTemplate变成T4模板。模板真的没什么特别的,只有1个属性(替换)声明如下:


<#@ property processor = " PropertyProcessor " name = " ModuleName " #>

I am writing a Guidance Package that is for an architecture similar to CAB - there is a shell and it can load modules. The solution has a folder called Modules and I want a recipe that can create a module in this solution folder. Say the developer wants a module called "ClientModule" the recipe will create another solution folder under Modules called "ClientModule" and under this sub-folder create 2 projects: One called "ClientModule" and one called "ClientModulePublisher".

To do this I looked at the SCSF guidance package and "butchered" my own version of their UnfoldModuleProjectAction action. This action is pretty straight-forward: create the solution folder and then call the "AddFromTemplate" method on the solution folder.

The problem comes in with substitution of $parameters$ in the template file. For the module project, I have a class called Module.cs with a placeholder called $ModuleName$. No matter how I try to do it, the parameter is never substituted for the actual ModuleName value (this is a RecipeArgument). This works for the SCSF package, but I cannot get it to work for my template, though I cannot see any differences.

So I tried to turn the VSTemplate into a T4 template. The template is really nothing fancy and has only 1 property (for substitution) declared as follows:

<#@ property processor="PropertyProcessor" name="ModuleName" #>

使用 TextTemplateAction action = new TextTemplateAction ())
{
Site.Container.Add(action);
action.Template = classTemplate;
action.Execute();
return action.Content;
}

调用Execute()方法时失败 - 异常表示属性"ModuleName"尚未提供。

但是,如果我使用配方调用T4变换,它可以很好地工作。操作如下所示:


< 操作 名称 = " RenderModuleClass " 输入 = " TextTemplateAction " 模板 = " Text\Module.cs.t4 " >
<
输入 名称 = " ModuleName " RecipeArgument = " ModuleName "
/>
<
输出 名称 = " 内容 "
/>
< /
操作 >


问题是,如何从代码中调用TextTemplateAction?我错过了"初始化"的东西吗?渲染引擎使用的字典(顺便提一下,如果我使用GetService< IDictionary>()来获取字典服务,那么ModuleName 就是。)

任何想法?

using (TextTemplateAction action = new TextTemplateAction())
{
   Site.Container.Add(action);
   action.Template = classTemplate;
   action.Execute();
   return action.Content;
}

This failed when the Execute() method was called - the exception said that property "ModuleName" had not been supplied.

However, if I use the recipe to call the T4 transform, it works perfectly. The Action looks as follows:


<Action Name="RenderModuleClass" Type="TextTemplateAction" Template="Text\Module.cs.t4">
   <
Input Name="ModuleName" RecipeArgument="ModuleName"
/>
   <
Output Name="Content"
/>
</
Action>


The question is, how can I call the TextTemplateAction from the code? Am I missing something that "initializes" the dictionary that the rendering engine uses (incidentally, if I use GetService<IDictionary>() to get the dictionary service, the ModuleName is there).

Any ideas?

推荐答案

您好

您需要设置T4模板的属性使用TextTemplateAction的Configure()方法。

像这样:

StringDictionnary dic = new StringDictionnary()
dic.Add(" ModuleName",value_of_module_name);
action.Configure(dic);
action.Execute()

希望有帮助


这篇关于从“CreateProject”中调用TextTemplateAction。行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆