1
votes

I'm newbie in .net core app. I'm developing a asp.net core (1.0 -> MVC6) targeting "net461" (full framework). Following is 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"
}

I needed to add a Class Library targeting framework 4.6.1 called OmniPayDataModel (Using telerik.DataAccess.Core):

enter image description here

My problem is I can't reference OmniPayDataModel.dll from my asp.net mvc project throwing following error:

enter image description here

However, it's possible to add csproj as references (targeting as project as project.json shows), but for some reasons when I build/rebuild OmniPayDataModel.dll no changes are being reflected when running solution (Eg: I put Dataannotations like displayname to my class models however <label asp-for="..." /> doesn't show the text to display). Following a snippet code:

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; }

Sorry if I'm wrong, but Why I can't add dll reference to my main project? Why main project added csproj as reference however changes are not reflected?

1

1 Answers

1
votes

I've found solution by myself.

For an Asp.Net core project there is no inconvennient to reference csproj (Class Library) and changes made into that class library are reflected well. I ran into a problem that made me attribute it to references incompatibility when root problem points to MetadataTypeattribute functionality into an Asp.Net core project.

I had to use ModelMetadataTypeAttribute instead of MetadataTypeAttribute from Microsoft.AspNetCore.Mvc.Core assembly. Decorating a metadata class (buddy class) follows same methodology of using Display(...), DisplayName(...), same for validators. No matter if the buddy class (Metadata Class) is located external from or internal to the model class.

However using MetadataTypeAttribute directly with the model class instead of a buddy class, works perfectly!

The only explanation I could give about this divergence is related with the new emerging Microsoft Asp.Net core technology, relocation of DLL process and functionalities.