ASP.NET Core RC2 separate models to project for cross-platform

.net-core-rc2 asp.net-core c# entity-framework-core

Question

I'm trying to separate the models into their own project for use in a xamarin cross-platform application using the new .net core class library. The issue i'm being presented with is:

Error image

My solution structure is as follows:

Solution structure image

My class library project.json is as follows:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final"
  },

  "frameworks": {
    "net451": { },
    "netstandard1.5": {
      "imports": [
        "dnxcore50",
        "portable-net452+win81"
      ]
    },
    ".netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  }
}

I'm referencing the class library in the web application but I'm unsure whether I've separated the models properly or not. I've tried to find a solution but because the ASP.NET Core framework is still very new there isn't much documentation or guidance on how to separate the models into it's own project. I'm hoping someone can provide some guidance on how to achieve this.

EDIT

Here is my web application project.json:

{
  "userSecretsId": "aspnet-Climbing.Web-d856be17-9b54-401e-98b2-4d6589fc7ff3",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
       "type": "build"
     },
     "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
       "version": "1.0.0-preview1-final",
       "type": "build"
     },
     "Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
     "Climbing.Domain": "1.0.0"
   },

  "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.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
      },
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": 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%" ]
  }
}

enter image description here

Thanks in advance for any help.

1
1
6/21/2016 9:41:09 PM

Accepted Answer

I've found the solution oddly enough it was a namespace problem that shouldn't be a issue. I'm convinced there is a bug somewhere in the underlying ASP.NET core RC2 framework although i might be wrong?

The problem arises when i change the namespace of the ApplicationUser in the class library from 'Climbing.Web.Models' to 'Climbing.Domain' - Which would be it's correct namespace. Once i changed this back to the 'Climbing.Web.Models' namespace the problem is fixed.

Edit: Dived a little deeper and realised i hadn't updated namespaces in views where ApplicationUser was referenced. Fixed this issue by updating the imports.

0
6/22/2016 12:09:54 AM

Popular Answer

It sounds as though you don't have the correct reference from your web project to your class project (or alternatively, you are missing a using statement.

To reference a class project from your web project, update your web project's project.json and a dependency similar to the following:

"dependencies": {
    "Climing.Domain": {
        "version": "1.0.0-*",
        "target": "project"
     },
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow