无法在asp.net vnext类库中使用必需属性
更新:当然,我试图添加using System.ComponentModel.DataAnnotations。它不起作用。
问题:我不能在asp.net vnext类库项目中使用Required属性。
案例: 1.添加默认设置的asp.net vnext类库项目。 2.创建带有字符串属性Name的类Human。 3.将Required属性添加到Name。 4.获取编译错误:
Error CS0246 The type or namespace name 'Required' could not be found (are you missing a using directive or an assembly reference?)
下面是我的project.json:
{
"version": "1.0.0-*",
"dependencies": {
"System.ComponentModel.Annotations": ""
},
"frameworks": {
"aspnet50": {
},
"aspnetcore50": {
"dependencies": {
"System.Runtime": ""
}
}
}
}
我也可以在asp.net vnext使用DataAnnotations,但不能在vnext类库。为什么?