Targeting .Net Framework 4.5 and .Net Standard libraries

I have a .NET library ( Products.SDK) that should be compatible with both the .NET Framework 4.5 and the .NET Standard 1.4.

(Later I will also create a NuGet package from this library)

My question is:

How to write code in this library? Given that both structures use different libraries / dependencies?

  • Will I have two separate projects with the same solution?

    Products.SDK.sln

    • Products.SDK.NetFramework
    • Products.SDK.NetStandard
  • Will I have only one project and use preprocessor directives #ifto define different classes inside the library?

    namespace Products.SDK
    {
        #if NETSTANDARD1_3
            public class ProductsApi
            {
                public string ApiUrl { get; set; }
            }
        #else
            public class ProductsApi
            {
                public string ApiUrl { get; set; }
            }
        #endif
    }
    

If parameter # 1 is correct, how can I make sure both projects are compiled using the same name / namespace ( Products.SDK)

, №2 , , .

PS:

.csproj

  <PropertyGroup>
    <TargetFrameworks>netstandard1.4;net45</TargetFrameworks>
  </PropertyGroup>
+4
1

- #if , . , , .

My Noda Time , - .

API , . , API , , net45. - :

  • A - net45
  • B - netstandard
  • C -

, . , X netstandard1.4 B, Y net45 A - Z, .NET 4.7, , X Y .

, . , , , net45, , netstandard, net45. ( , TypeInfo netstandard, , Type net45. TypeInfo .)

+7

Source: https://habr.com/ru/post/1684200/


All Articles