如何说服 VS2008 运行 .tt 模板文件?
按照单音节单词演练应该可以让我的演示应用程序正常工作,对吧?但到目前为止我摔倒了两次,而且我只完成了 5 个步骤过程中的第 4 步:(
1 在 Visual Studio 2008 中创建一个新项目
完成了,耶!
2 将连接字符串添加到您的 Web/App.config,给它一个名称,并将其指向一个有效的数据库
完成,耶!
3 抓住包含 T4 模板(“tt”扩展名)的文件夹,并找到名为“_Settings”的文件夹,然后在记事本中打开它并设置将“ConnectionStringName”的值更改为您刚刚创建的连接字符串的名称,
哎呀,没有一个名为“_Settings.tt”的字符串 - 有一个名为“Settings.ttinclude”的字符串 - 这是我需要编辑的吗?也需要更改名称吗?
所以我进行编辑以使用我的连接字符串名称、数据库名称和命名空间名称,并将其另存为“_Settings.tt”
4 将包含 T4 模板的文件夹放入您的 Visual 项目中。 Studio 2008 将看到这些并执行模板代码,创建您的类
我将文件夹拖到我的 VS2008 ConsoleApplication1 项目中,但没有任何反应。
所有文档和所有内容都表明 VS2008 将神奇地理解 .tt 扩展名并立即采取行动。代表我做一些严肃的工作。
我会等待,但地狱可能会结冰,所以我去寻找线索。不,每个人都认为它是自动的、非接触式的、神奇的。
5 大功告成——去吃烤肉吧。
我没有烤肉串。我还没有完成。我需要帮助。
Following the words-of-one-syllable walkthrough should get my demo app working, right? But I fell down twice so far and I'm only up to step 4 in the 5 step process :(
1 Create a new project in Visual Studio 2008
Done that, yayy!
2 Add a connection string to your Web/App.config, give it a name, and point it to a valid database
Done that, yayy!
3 Grab the folder containing the T4 templates (the "tt" extensions) and locate the one that named "_Settings". Open it up in Notepad and set the value for "ConnectionStringName" to the name of the connection string you just made.
Whoops. There isn't one named "_Settings.tt" - there's one named "Settings.ttinclude" - is that the one I need to edit? Do I need to change the name too?
So I take a punt and edit it to use my connection string name and database name and namespace name, and save it as "_Settings.tt"
4 Drop the folder with the T4 templates into your project. Visual Studio 2008 will see these and execute the template code, creating your classes
I drag the folder into my VS2008 ConsoleApplication1 project and nothing happens.
All the docs and everything suggests that VS2008 will magically understand the .tt extension and immediately sprig in to action to do some serious work on my behalf.
I'd wait, but Hell might freeze over, so I go searching for clues. Nope, everybody thinks it's automatic, no-touch, magic.
5 You're done - go have a Kabob.
No kebab for me. I'm not done. I need help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
右键单击并“运行自定义工具”
您使用的是express吗?我今天早上读了一篇文章,抱怨在亚音速中使用 t4s 与 VS 表达...在此处配置它的说明 Visual Web Developer Express 中的 SubSonic ASP.NET MVC 示例
right click and "run custom tool"
Are you using express? I read a post this morning moaning about using the t4s in subsonic with VS expres... instrunction on configuring it in here SubSonic ASP.NET MVC sample in Visual Web Developer Express
尝试向您的项目添加一个新的空白 TT 文件 - VS 应该自动将工具“TextTemplateFileGenerator”与该文件关联起来。在文本编辑器(或VS)中打开原始TT,并将内容剪切并粘贴到空白TT中。
或者,您可以转到 TT 文件的“属性”窗口,并将“自定义工具”属性设置为“TextTemplateFileGenerator”。
这应该为文件的上下文菜单提供“运行自定义工具”选项。
并且 - 您不能引用该文件 - TT 文件必须位于项目文件夹内。不知道为什么,但我无法让其正常工作。
Try adding a new blank TT file to your project - VS should automatically associate the tool "TextTemplatingFileGenerator" with the file. Open the original TT in a text editor (or VS) and cut-and-paste the content into the blank TT.
Or, you could go to the Properties window for your TT file and set the Custom Tool property to "TextTemplatingFileGenerator".
This should provide the "Run Custom Tool" option to the file's context menu.
AND - you can't have a Reference to the file - the TT file has to be located within the Project's folder. Don't know why, but I can't get the to work otherwise.
我真的完蛋了。
Vista(旗舰版)花了 25 分钟在 DVD 驱动器中安装安装光盘,然后声明“无法安装 Visual Studio 2008 SP1”。
我想我安装的东西不仅会干扰 VS2008 的工作方式,还会干扰安装程序的工作方式,因此无法修复。混蛋!
我挖出了一个旧的备份硬盘映像,是我还在使用 XP Pro 时的。那已经安装了VS2008,但我不想回滚Vista,所以将它加载到旧PC上(最终)。
现在 .tt 文件被神奇地识别了,VS 处理它们并生成 C# 代码 - 耶!
但这也不全是好消息……
旧电脑是一头驴。处理 .tt 文件需要很长时间,其他一切也都很慢。我需要让我的 Vista 主机器恢复正常工作,但至少我现在可以看到这个过程是如何工作的。
下一个问题是截屏视频与 .zip 文件中的内容不匹配......
I'm truly screwed.
Vista (Ultimate) spends 25 minutes thrashing away at the install disc in the DVD drive and then declares "Unable to install Visual Studio 2008 SP1".
I guess I've installed something that's interfering not only with the way VS2008 works, but also with the way the installer works so it can't be repaired. Bugger!
I dug out an old backup hard disc image, from the days when I was still using XP Pro. That has VS2008 installed, but I didn't want to roll back Vista, so loaded it onto an old PC (eventually).
Now the .tt files are magically recognised and VS processes them and generates the C# code - yayy!
But it's not all good news...
The old PC is a donkey. Processing the .tt files takes an age, and everything else is so slow too. I need to get my main Vista machine back to full working, but at least I can see now how the process works.
Next quibble is the mismatch between the screencast and what comes down in the .zip file...
确保您的解决方案/项目是“asp.net mvc”或“ClassLibrary”,以便VS识别.tt
be sure that your solution/project is an "asp.net mvc" or "ClassLibrary" in order the VS to recognize the .tt
请参阅无法将文件拖动到解决方案资源管理器
基本上,您如果您以管理员身份运行 Visual Studio,则无法将文件拖到 Visual Studio 中。由于 Windows 资源管理器无法以管理员身份运行,唯一的方法是不以管理员身份运行 Visual STudio,这样您就可以将文件拖到 Visual STudio 中。
See Can't drag files to Solution Explorer
basically, you can't drag files into Visual Studio if you're running it as Administrator. Since Windows Explorer can't be run as Administrator, the only way is to not run Visual STudio as an admin, That will allow you to drag files into Visual STudio.
我对 Windows 7 和 VS 2010(以管理员身份运行)也有同样的挫败感。我也没有烤肉串。我尝试过运行自定义工具,该工具也可以执行 Jack Diddly。我的项目是类库。
I have the same frustration with Windows 7 and VS 2010 (running as Admin). No kabob for me either. I've tried running custom tool which also does Jack Diddly. My proj is class library.