Asp.Net 5 class 个库 DataAnnotation 错误
Asp.Net 5 class library DataAnnotation errors
我刚刚将一个 class 库项目添加到我的新解决方案中,并且只提供了新的 class 库类型的选项。我创建了我的域 classes,它使用来自 System.Component.DataAnnotations 的 EF 数据注释。 classes 本身没有错误,但项目不会生成。我收到这些错误。
Severity Code Description Project File Line
Error CS0234 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4 C:\Users\Thomas Donino\Documents\GitHubVisualStudio\TraderToolkit2016\TraderToolkit2016.DomainClasses\AppClasses\DailyClose.cs
我引用了程序集。为什么我会收到这些错误?
这是我的 project.json 文件,DataAnnotations 从 VS 右键单击自动添加。
{
"version": "1.0.0-*",
"description": "TraderToolkit2016.DomainClasses Class Library",
"authors": [ "Thino" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
这意味着您正在使您的项目与 2 个平台兼容。一个是 net451 另一个是 dotnet5.4.
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
这意味着您仅将 System.ComponentModel.DataAnnotations 的引用添加到 net451 目标。这就是您收到以下错误的原因:
are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4
注意错误消息末尾的 5.4。
现在的解决方案是,如果您不需要 dotnet5.4,请将其删除,或者添加对 dotnet5.4 的 System.ComponentModel.DataAnnotations 引用。你可以通过简单地安装这个 nuget 包来做到这一点:
https://www.nuget.org/packages/System.ComponentModel.Annotations/4.0.11-beta-23516
或者简单地修改文件,使其看起来像这样:
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
}
我刚刚将一个 class 库项目添加到我的新解决方案中,并且只提供了新的 class 库类型的选项。我创建了我的域 classes,它使用来自 System.Component.DataAnnotations 的 EF 数据注释。 classes 本身没有错误,但项目不会生成。我收到这些错误。
Severity Code Description Project File Line Error CS0234 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4 C:\Users\Thomas Donino\Documents\GitHubVisualStudio\TraderToolkit2016\TraderToolkit2016.DomainClasses\AppClasses\DailyClose.cs
我引用了程序集。为什么我会收到这些错误?
这是我的 project.json 文件,DataAnnotations 从 VS 右键单击自动添加。
{
"version": "1.0.0-*",
"description": "TraderToolkit2016.DomainClasses Class Library",
"authors": [ "Thino" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
这意味着您正在使您的项目与 2 个平台兼容。一个是 net451 另一个是 dotnet5.4.
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "4.0.0.0"
}
},
这意味着您仅将 System.ComponentModel.DataAnnotations 的引用添加到 net451 目标。这就是您收到以下错误的原因:
are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4
注意错误消息末尾的 5.4。
现在的解决方案是,如果您不需要 dotnet5.4,请将其删除,或者添加对 dotnet5.4 的 System.ComponentModel.DataAnnotations 引用。你可以通过简单地安装这个 nuget 包来做到这一点:
https://www.nuget.org/packages/System.ComponentModel.Annotations/4.0.11-beta-23516
或者简单地修改文件,使其看起来像这样:
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
}