我是.net核心应用中的新手。我正在开发一个针对“net461”(完整框架)的asp.net核心(1.0 - > MVC6)。以下是project.json:
{
"dependencies": {
"KendoUICore": "2016.2.607",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": "build"
},
"Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.CompilationAbstractions": "0.0.1-alpha",
"System.Linq.Queryable": "4.0.0",
"Telerik.DataAccess.Core": "2016.1.224.1",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNet.Identity.Owin": "2.2.1",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Microsoft.AspNetCore.Session": "1.0.0",
"jQuery": "3.0.0.1"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.Extensions.SecretManager.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net461": {
"dependencies": {
"OmniPayDataModel": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"userSecretsId": "aspnet-OmniAdminConcept-Mvc6CoreWin-20160622113707"
}
我需要添加一个名为OmniPayDataModel的类库目标框架4.6.1(使用telerik.DataAccess.Core):
我的问题是我无法从我的asp.net mvc项目中引用OmniPayDataModel.dll引发以下错误:
但是,可以添加csproj作为引用(作为project.json显示的项目),但由于某些原因,当我构建/重建OmniPayDataModel.dll时,运行解决方案时没有反映出任何变化(例如:我把Dataannotations像displayname到我的班级模型但是<label asp-for="..." />
没有显示要显示的文本)。以下代码段:
namespace DataModel
{
[MetadataType(typeof(Directory.DirectoryMetadata))]
public partial class Directory
{
internal sealed class DirectoryMetadata
{
public DirectoryMetadata()
{
}
[Display(Name = "Id Directorio")]
[Required()]
public string DirectoryId
{ get; set; }
[Display(Name = "Nombre Completo")]
[Required()]
public string DirectoryFullName
{ get; set; }
抱歉,如果我错了,但为什么我不能将dll引用添加到我的主项目中?为什么主项目添加了csproj作为参考,但是没有反映出变化?
答案 0 :(得分:1)
我自己找到了解决方案。
对于Asp.Net核心项目,引用csproj(类库)没有任何不便之处,并且很好地反映了对该类库所做的更改。当root问题指向Asp.Net核心项目中的MetadataTypeattribute功能时,我遇到了一个问题,使我将其归因于引用不兼容。
我必须使用 ModelMetadataTypeAttribute 而不是 Microsoft.AspNetCore.Mvc.Core 程序集中的 MetadataTypeAttribute 。装饰元数据类(伙伴类)遵循使用Display(...),DisplayName(...)的相同方法,对于验证器也是如此。无论伙伴类(元数据类)是位于模型类的外部还是内部。
然而,将MetadataTypeAttribute直接与模型类而不是伙伴类一起使用,效果非常好!
我能解释的唯一解释是新出现的Microsoft Asp.Net核心技术,DLL过程和功能的重新定位。