【问题标题】:Referencing Class Library Framework 4.6.1 from asp.net core .net full framework 4.6.1从 asp.net core .net full framework 4.6.1 引用 Class Library Framework 4.6.1
【发布时间】:2016-07-14 20:01:28
【问题描述】:

我是 .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(使用 telerik.DataAccess.Core)的类库定位框架 4.6.1:

我的问题是我无法从我的 asp.net mvc 项目中引用 OmniPayDataModel.dll 并引发以下错误:

但是,可以将 csproj 添加为引用(以 project.json 显示的项目为目标),但由于某些原因,当我构建/重建 OmniPayDataModel.dll 时,运行解决方案时没有反映任何更改(例如:我把 Dataannotations 像displayname 到我的班级模型,但是<label asp-for="..." /> 不显示要显示的文本)。在一个 sn-p 代码之后:

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 作为参考,但更改没有反映?

【问题讨论】:

    标签: c# visual-studio asp.net-core-mvc asp.net-core-1.0


    【解决方案1】:

    我自己找到了解决办法。

    对于 Asp.Net 核心项目,引用 csproj(类库)并没有什么不便,对该类库所做的更改也得到了很好的反映。当根问题指向 Asp.Net 核心项目的 MetadataType 属性功能时,我遇到了一个问题,这使我将其归因于引用不兼容。

    我必须使用 ModelMetadataTypeAttribute 而不是 Microsoft.AspNetCore.Mvc.Core 程序集中的 MetadataTypeAttribute。装饰元数据类(伙伴类)遵循使用 Display(...)、DisplayName(...) 的相同方法,对于验证器也是如此。无论伙伴类(元数据类)是位于模型类的外部还是内部。

    但是,直接将 MetadataTypeAttribute 与模型类而不是伙伴类一起使用,效果很好!

    我能给出的关于这种分歧的唯一解释与新兴的 Microsoft Asp.Net 核心技术、DLL 进程和功能的重定位有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 2020-12-14
      • 1970-01-01
      • 2017-10-12
      • 2017-10-07
      • 1970-01-01
      相关资源
      最近更新 更多