Search code examples
c#.netasp.net-core.net-core.net-standard-1.5

Using Full .NET API's with NetStandard 1.5


I am using the new netstandard1.5 target framework in my class library. Are you still able to use pre-processor directives to add additional functionality for the full .NET framework?

For example, I want to use System.ServiceModel.Syndication with netstandard1.5 and at the time of writing, this is only available on .NET 4.5. How can I achieve this?


Solution

  • You can target multiple target frameworks at the same time within the same project.json. One could be netstandard1.5 while others could be net45.

      "frameworks": {
        "netstandard1.5": { },
        "net45": {
          "frameworkAssemblies": {
            ...
          }
        }
      }
    

    In that case you could "pre-processor" directives for NET_45 and NETSTANDARD1_5. The result would be a nuget package with two implementations (one for net45 and one for netstandard1.5 of the same contract (if packed).

    You cannot target solely netstandard1.5 and then use conditional programming to opt-in a net45 framework assembly.