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

I'm having a hard time trying to migrate from 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 separated 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 keyworkd in the class library and it does not support it. The MVC project supports without any problem. I guess it's because of the differente .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?


  • 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"
        }
      }
    }
    
    链接地址: http://www.djcxy.com/p/92794.html

    上一篇: SAML 2.0中的收件人与受众群体

    下一篇: 我可以在.NET标准类库中使用动态吗?