4

I have an existing codebase written in .Net 4.5.x. I'm trying to create some new .Net Core services with the aim of eventually migrating the codebase to .Net Core piecemeal. I'd like the option to (eventually) deploy these services to small Linux servers, so I've targeted the first of them at .Net Core rather than the .Net Framework.

All of the existing code should communicate with the new services via standard REST endpoints. Since it's all REST, all that will actually go over the wire is JSON. No problems there.

I'm hoping to avoid some code reuse by having some shared Model projects which both the legacy and new services can utilize. I know this would be possible if the new services were .Net Core projects targeted at the .Net Framework, but I'm hoping there's a way to have a middle layer support legacy .Net Framework code and new .Net Core targeted code.

Is this possible, or is my only option to have the DTO classes duplicated in two projects until everything can eventually be ported over? Alternatively, am I architecting this all wrong in the first place and should I actively want dto classes on both ends?

Necoras
  • 6,743
  • 3
  • 24
  • 45
  • Possible duplicate of [.net core classlibrary calling .net framework class library](http://stackoverflow.com/questions/37608032/net-core-classlibrary-calling-net-framework-class-library) – nvirth Dec 14 '16 at 12:06

2 Answers2

0

If I get it correct, your goal is to have an application (client/web/service) that should be able to run across platforms (Windows/Linux/MacOS).Therefore, the best choice in hand is to use .NET Core as its run-time (CoreCLR). In my experience, I never hand to write heavy weight DTO those are platform specific. So my suggestion would be to look at your desk and isolate DTOs those are platform specific and find an alternative or choose a alternate for that.

S.N
  • 4,910
  • 5
  • 31
  • 51
0

You can use Shared Projects to host your DTO classes and reference that project in both the .Net Core and 4.5.x projects.

You can have a look at this link if you're not familiar with shared projects http://www.c-sharpcorner.com/UploadFile/7ca517/shared-project-an-impressive-features-of-visual-studio-201/ or just do a quick search and you'll find lots of information.

Essentially, shared projects allow you to reference/share code files across multiple projects instead of referencing their binaries/assemblies

KMoussa
  • 1,568
  • 7
  • 11
  • Hrm, I tried this, but the Shared Project menu isn't available when adding references to my Asp.Net Core project. I checked and it doesn't show up with a standard ASP.Net MVC project either, though it is available for use by a standard class library project. I'm not sure if that's as intended (because it can only be shared to certain project types and/or frameworks), or if it's a bug in VS. – Necoras Oct 19 '16 at 20:37
  • Haven't tried it on Asp.net, but if it's not working you can have one shared project with your DTO then 2 class libraries (one for .net core and the other for 4.5) that just reference the shared projects, and then you reference those into you asp.net and other projects targeting either .net core or 4.5 – KMoussa Oct 19 '16 at 20:47