我创建了一个 .NET Core(包)库项目,它有一个像这样的类:
public class Subscriber //: Representation
{
[Required]
public SubscriberDef Info;
public Guid ProviderID;
}
无论我做什么,编译器都不满意 [Required]
属性。我经常被告知:
NET Framework 4.5.1 - Not Available
NET Platform 5.4 - Available
我的 project.json 最初看起来像这样:
"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 Core 项目,那么我可以自由地拥有两个尊重数据注释并可以编译的框架:
"frameworks": {
"dnx46": { },
"dnxcore50": { }
},
我想如果数据注释在 ASP.NET Core 中工作,那么它们肯定也能在 .NET Core 中工作吗?
是我做错了什么,还是数据注释目前真的无法用于 .NET Core fullCLR?
最佳答案
http://packagesearch.azurewebsites.net/?q=requiredattribute
这是一个新平台,所以请先了解如何搜索您需要的 NuGet 包。
关于c# - 在 .NET Core 的完整/核心平台中启用 DataAnnotations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36535712/