如何在项目中使用 T4 自定义脚手架?
我正在使用 T4Scaffolding做一些 C# 代码生成。考虑以下项目结构:
我在模板项目中创建了一个自定义脚手架。现在我想为 Dummy 项目运行它,但出现此异常:
我如何在项目中使用自定义脚手架?
问题是:我在 TFS 中有 20 个项目,我想在 1 个中心位置管理 t4 模板的代码。
I'm using T4Scaffolding to do some do some C# code generation. Consider the following project structure:
I've created a custrom scaffolder in the Templates project. Now I would like to run it for the Dummy project, but I get this exception:
How can I use Custom Scaffolding over projects?
The thing is: I've got 20 projects in TFS and I would like to manage the code of the t4 templates in 1 central location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这只是将 CodeTemplates/Scaffolders/BaseSuperModule 中的文件和目录复制到虚拟项目中,然后调用 Scaffold 命令的问题。
编辑:这很有道理。我正在学习如何将自定义 t4Scaffolding 代码移动到 NuGet 包中。我认为这将是最适合您的路线。一旦我弄清楚,我会立即更新我的答案。
编辑2:我找到了这篇文章,我浏览了它并有一个有效的示例。尝试一下,如果我可以提供进一步的帮助,请告诉我。
http://geekswithblogs.net/michelotti/archive/2011/07/14/leverage-t4scaffolding-for-wcf-web-api.aspx
I think it is just be a matter of copying the files and Directories located in CodeTemplates/Scaffolders/BaseSuperModule into the Dummy Project and then calling the Scaffold command.
Edit: That makes perfect sense. I am in the middle of learning how to move custom t4Scaffolding code into a NuGet package. I think that would be the route that would work best for you. I will update my answer as soon as I figure it out.
Edit 2: I found this article and I went through it and have a working example. Give it a try and let me know if I might be able to help further.
http://geekswithblogs.net/michelotti/archive/2011/07/14/leverage-t4scaffolding-for-wcf-web-api.aspx
我认为诀窍是从模板项目中进行脚手架,并将要生成的项目名称传递给例如,
您必须将字符串传递给 Add-ProjectItemViaTemplates 中的 -Project 参数,而不是项目对象
如果您已经知道各种脚手架需要应用到的项目,那么您可以在脚手架中为ProjectName设置默认值。
MvcScaffolding 包中有一些这样的示例。
I think the trick is to do the scaffolding from the Templates project and pass in the name of the project you want to generate into e.g.
You must pass a string to the -Project argument in Add-ProjectItemViaTemplates not a project object
If you already know the projects that the various scaffolders need to apply to, then you can set a default value for ProjectName in the scaffolder.
There's some examples of this in the MvcScaffolding package.