【问题标题】:DataAnnotations namespase error when use CodeTemplates inside the ASP.NET MVC project在 ASP.NET MVC 项目中使用 CodeTemplates 时出现 DataAnnotations 命名空间错误
【发布时间】:2011-11-20 10:02:30
【问题描述】:
我想更改 ASP.NET MVC 的默认代码生成器并使用Hanselman Way,但是从控制器添加视图时出现如下错误:
这是关于两个未在程序集中提及的命名空间:System.ComponentModel 中的 1-DataAnnotations 系统.Data 中的 2-Linq
编辑:
还有一个警告:
IntelliSense 不适用于免费版中的程序集“System.ComponentModel.DataAnnotations”。请考虑从 t4-editor.tangible-engineering.com 购买专业版
我还清除了每个模板的自定义工具属性。
我该如何解决?
【问题讨论】:
标签:
asp.net
asp.net-mvc
asp.net-mvc-3
t4
【解决方案1】:
1-当然使用标准的 CodeTemplates 其中之一在这里:
C:\Program Files(或 x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp(或 Visual Basic)\Web\MVC(或 2)3\CodeTemplates
2-清除每个模板的 CustomTool 属性。
3-(如果还不行)重启 VS 或者关闭所有打开的 Visual Studio 并再次打开你的项目。
4-(如果还不行)重启IIS,可能需要重启电脑。
5-(如果还不行)更新EntityFramework并重启vs
6-(如果还不行)打开Visual Studio,到Tools-->Extension Manager in Online Gallery 搜索并安装:NuGet Package Manager(如果还没有安装)重启Visual Studio,现在打开 Tools-->Library Package Manager-->Manage NuGet Packages.. 在在线部分:搜索 DataAnnotationExtension 或 DataAnnotationExtension.MVC3 并安装它并重新启动 VS。
7-(如果还没有工作)我希望尽快工作。
【解决方案2】:
您的 T4 模板是否缺少以下程序集引用?
<#@ assembly name="System.ComponentModel.DataAnnotations" #>
<#@ assembly name="System.Data.Linq" #>
【解决方案3】:
关闭 Visual Studio
删除报错信息中C:\Users\Administrator\AppData\Local\Temp\上方显示的Temp文件夹内容,打开Visual Studio,否则可能是T4模板出错。