Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use dynamic in a .NET Standard class library?

I'm having a hard time trying to migrate from a regular Windows desktop development to ASP.NET Core MVC. One issue I'm coming across is to create my solution. I would like to remove everything that is not UI related from the default project that ships with VS 2015 and put into a separate project.

I noticed that ASP MVC Core references to .NETCoreApp and the Class Library project references to .NETStandard.

My problem is that I need to use the dynamic keyword in the class library and it does not support it. The MVC project supports without any problem. I guess it's because of the different .NET versions.

  1. What is the difference between NETStandard and NETCoreApp?

  2. Can I create a class library that uses the same reference as the MVC project so I can use the dynamic keyword on it?

  3. Or should I stick with a one project solution with all domain, infrastructure, etc in the same place?

like image 697
rbasniak Avatar asked Aug 05 '16 22:08

rbasniak


People also ask

What is the difference between Class Library .NET standard and class library .NET core )?

Net standard has a higher version then more APIs/inbuilt library like “System. data” are available. So based on project requirements . Net standard library needs to be created.

When should you use the .NET standard class library project type?

When should we use one over the other? The decision is a trade-off between compatibility and API access. Use a . NET Standard library when you want to increase the number of applications that will be compatible with your library, and you are okay with a decrease in the .

What is .NET standard class library?

. Net Standard is a specification which dictates what the Base Class Libraries of different . Net platforms should implement to unify the Base Class Libraries of different . Net Platforms.

What is the difference between .NET Standard and PCL portable class libraries?

NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.


1 Answers

Yes, it's possible to put non-UI code into a separate library. As you guessed, netcoreapp1.0 is for applications (console or web), and netstandard1.X is for class libraries.

A .NET Standard class library shouldn't have any problem with the dynamic keyword. You do need to reference NETStandard.Library, though. Here's a barebones working library example:

MyLibrary/project.json

{
   "description": "My awesome library",
   "dependencies": {
      "NETStandard.Library": "1.6.0"
   },
   "frameworks": {
      "netstandard1.3": { }
   }
}

Your ASP.NET Core web application can reference this library if it's part of the same solution like this:

{
  (... other stuff)

  "dependencies": {
    "MyLibrary": {
      "target": "project"
    }
  }
}
like image 135
Nate Barbettini Avatar answered Oct 22 '22 23:10

Nate Barbettini