无法获取T4MVC与VS2010和ASP.NET MVC 2的工作 [英] Cannot get T4MVC to work with VS2010 and ASP.NET MVC 2

查看:173
本文介绍了无法获取T4MVC与VS2010和ASP.NET MVC 2的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给T4MVC模板添加到我的项目,但我遇到了一些问题。我去codePLEX和下载最新版本T4MVC ,并根据该说明我刚才的两个文件复制 T4MVC.tt T4MVC.Settings.t4 进入我的网站的根应用程序。

随即,我得到了以下错误:

T4MVC.cs (生成文件):

命名空间不能直接包含成员如字段或方法

T4MVC.tt (在code生成模板):

编译转换:类型或命名空间名称ITextTemplatingEngineHost'找不到(是你缺少using指令或程序集引用?)

当我打开 T4MVC.cs ,它只包含一行:

  ErrorGenerating code

我发现<一个href=\"http://stackoverflow.com/questions/1867329/does-t4mvc-work-with-visual-studio-2010-beta-2-and-net-4\">this帖子该建议只是再建,但解决方案不解决我的问题 - 事实上,它不会改变任何事情。我应该怎么办?


解决方案

好吧,我想通了。问题是,既然T4MVC包的最后一个版本显然,微软改变了 ITextTemplateHost 接口的位置,所以我需要导入另一个命名空间。此外,这些命名空间的.dll 文件的默认ASP.NET MVC模板项目不会被导入。这是我做过什么,使其工作:


  1. (我的机器上的搜索路径在括号中)添加到下面的.dll文件引用:


    • Microsoft.VisualStudio.TextTemplating.10.0.dll (*C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\Microsoft.VisualStudio.TextTemplating.10.0\\v4.0_10.0.0.0__b03f5f7f11d50a3a\\Microsoft.VisualStudio.10.0.dll*)


    • Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll (*C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0\\v4.0_10.0.0.0__b03f5f7f11d50a3a\\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll*)



  2. 请确保以下的命名空间在 T4MVC.tt (只要按照这已经是文件中的语法)。

    对进口

    • Microsoft.VisualStudio.TextTemplating


    • Microsoft.VisualStudio.TextTemplating.Interfaces



  3. 删除所有产生code文件(他们会如果展开 T4MVC.tt 在Solution Explorer中出现)。


  4. 生成项目。如果未生成文件,打开 T4MVC.tt ,编辑的东西,不保存和建设。应该这样做!


I'm trying to add the T4MVC templates to my project, but I'm experiencing some problems. I went to Codeplex and downloaded the latest version of T4MVC, and according to the instructions I just copied the two files T4MVC.tt and T4MVC.Settings.t4 into the root of my web application.

Immediately, I got the following errors:

From T4MVC.cs (generated file):

A namespace cannot directly contain members such as fields or methods

From T4MVC.tt (the code generating template):

Compiling transformation: The type or namespace name 'ITextTemplatingEngineHost' could not be found (are you missing a using directive or an assembly reference?)

When I open T4MVC.cs, it only contains one line:

ErrorGeneratingCode

I found this post that suggests just building again, but that solution does not solve my problem - in fact, it doesn't change a thing. What should I do?

解决方案

OK, I figured it out. The problem was that apparently since the last release of the T4MVC package, Microsoft changed the location of the ITextTemplateHost interface, so I needed to import another namespace. Also, the .dll files with these namespaces aren't imported in the default ASP.NET MVC template project. This is what I did to make it work:

  1. Add references to the following .dll files (search paths on my machine in brackets):

    • Microsoft.VisualStudio.TextTemplating.10.0.dll (*C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.10.0\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.10.0.dll*)

    • Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll (*C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll*)

  2. Make sure the following namespaces are both imported in T4MVC.tt (just follow the syntax that's already in the file).

    • Microsoft.VisualStudio.TextTemplating

    • Microsoft.VisualStudio.TextTemplating.Interfaces

  3. Delete all generated code files (they'll appear if you expand the T4MVC.tt in Solution Explorer).

  4. Build project. If no files are generated, open T4MVC.tt, edit something, don't save and build. That should do it!

这篇关于无法获取T4MVC与VS2010和ASP.NET MVC 2的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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