1

EDIT :

In the original question, I mentioned ASP.NET 5. It DOES NOT target the future release of .Net Classic / .Net Core planned for 2021. The question was asked at the time of the first beta versions of .Net Core 1.0. At this time, it was named ASP.Net 5 / .Net vNext / DNX.

As such, in the original question, please understand version numbers as following :

  • ASP.Net 5 => ASP.Net Core 1.0 beta
  • ASP.NET MVC 6 => ASP.NET Core MVC 1.0 beta
  • Entity Framework 7 => Entity Framework Core 1.0 beta

I am starting a new project in ASP.Net 5 and ASP.NET MVC 6, running on DNX, and started out from the default MVC 6 template of Visual Studio 2015. My data layer uses Entity Framework 7 with the code-first approach.

My Web application project in then in the new approach : xproj file, referencing different json config files (project, solution, npm and bower managers).

As a long time .Net developer, I always had my Data Access Layer in an .Net Assembly projet (or several), then referenced into each of my client-side project (e.g. : a web application, a web API, console applications, or unit testing projects).

My questions are :

  • is that still possible (I guess so)
  • what is the recommended approach (an assembly project or an internal nuget package)
  • how do you set that up (which kind of project template should be used to be working with a xproj web application)
kall2sollies
  • 1,429
  • 2
  • 17
  • 33
  • Yes. It is possible. Keeping that project in same solution and doing a project reference vs creating nuget is totally up to you. I am not sure what xproj file you are mentioning here. In the new MVC6 templates, web project won't have a project file like previous versions had. It is the project.json plays role of organizing dependencies etc – Shyju Feb 25 '16 at 13:45
  • Well I actually have a xproj file, and the project was created just one month ago, with RC versions of DNX and MVC6 up to date. The syntax is XML as of csproj files, does not contain references of any kind (which actually rely on project.json file). – kall2sollies Feb 25 '16 at 13:50

2 Answers2

1

It is possible but you have to manage this issue : https://github.com/aspnet/dnx/issues/3047

You have to remove any localization support by adding this to your Startup's configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    //...
    var localizationOptions = new RequestLocalizationOptions()
    {
        SupportedCultures = new List<CultureInfo> { new CultureInfo("") },
        SupportedUICultures = new List<CultureInfo> { new CultureInfo("") }
    };

    var invariantCulture = new RequestCulture(new CultureInfo(""), new CultureInfo(""));

    app.UseRequestLocalization(localizationOptions, invariantCulture);
    //...
}

Otherwise you will have this FileNotFoundException :

FileNotFoundException: Couldn't find file EntityFramework.resources.
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
AdrienTorris
  • 9,111
  • 9
  • 34
  • 52
0

Following this SO Question (What are my options for sharing code between DNX / ASP.NET 5 projects (project.json / xproj) and other C# projects (csproj) within a single solution?) - which is close to mine by the way - I decided to give a try to the default approch, which is a "Class Library (Package)" project.

I've had to change references to runtimes in order to have it working :

  • my main project.json referenced frameworks dnx451 and dnxcore50.
  • the Class Library (Package) created a project.json file with frameworks net451 and dotnet5.4.

I've had to change the latter to dnx451 and dnxcore50 to make everything work.

That remains an unexplained solution, because AFAIK, dnx451 and dnxcore50 should be now replaced by dnx451 and dnxcore50, but I had to do the opposite, or my existing references (including "EntityFramework.Commands": "7.0.0-rc1-final") would be broken.

Anyway that solution is working, so for those interested in separating their EF logic in a shared project, I would recommand reading this article, which explains how to enable ef commands (migrations and database update) in a class library project : http://www.jerriepelser.com/blog/moving-entity-framework-7-models-to-external-project

Community
  • 1
  • 1
kall2sollies
  • 1,429
  • 2
  • 17
  • 33