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.
What is the difference between NETStandard and NETCoreApp?
Can I create a class library that uses the same reference as the MVC project so I can use the dynamic keyword on it?
Or should I stick with a one project solution with all domain, infrastructure, etc in the same place?
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 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 .
. 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.
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.
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"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With