C# 在.NET core的完整/核心平台中启用DataAnnotation
我创建了一个.NET核心(包)库项目,它有一个类,如下所示:C# 在.NET core的完整/核心平台中启用DataAnnotation,c#,asp.net-core,.net-core,C#,Asp.net Core,.net Core,我创建了一个.NET核心(包)库项目,它有一个类,如下所示: public class Subscriber //: Representation { [Required] public SubscriberDef Info; public Guid ProviderID; } "frameworks": { "net451": { "dependencies": { "WebApi.Hal": "2.6.0", } }, "do
public class Subscriber //: Representation
{
[Required]
public SubscriberDef Info;
public Guid ProviderID;
}
"frameworks": {
"net451": {
"dependencies": {
"WebApi.Hal": "2.6.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",
}
}
},
"dependencies": {
"Excqape": "0.7.0",
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
无论我做什么,编译器都不满意[Required]
属性。我经常被告知:
NET Framework 4.5.1 - Not Available
NET Platform 5.4 - Available
我的project.json最初是这样的:
public class Subscriber //: Representation
{
[Required]
public SubscriberDef Info;
public Guid ProviderID;
}
"frameworks": {
"net451": {
"dependencies": {
"WebApi.Hal": "2.6.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",
}
}
},
"dependencies": {
"Excqape": "0.7.0",
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
我尝试将目标框架名字对象(TFM)从net451
切换到net46
。不走运。我尝试了两个框架使用的System.ComponentModel.Annotations的不同版本,但仍然没有成功
特别奇怪的是,如果我创建了一个ASP.NET核心项目,那么我就可以自由地拥有两个框架,其中数据注释受到尊重并将编译:
"frameworks": {
"dnx46": { },
"dnxcore50": { }
},
我想如果数据注释在ASP.NET内核中工作,那么它们肯定也能在.NET内核中工作
我是否做错了什么,或者目前.NET Core fullCLR确实无法使用数据批注?
这是一个新平台,请先了解如何搜索所需的NuGet软件包。PackageSearch-这是一个非常有用的网站,我现在知道了,谢谢!