Conditional compilation symbol for a .NET Core class library

后端 未结 3 1990
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 14:45

I have created a .NET Core R2 class library and have some common code that I use for several different platforms.

Some of the code is not valid in the .NET Core plat

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 15:00

    Since xproj was discontinued, here is how it is done in the new Visual Studio 2017 .csproj files.

    
        NET_CORE
    
    

    Then instead of:

    private TypeInfo GetTypeInfo(Type type)
    {
        #if NETSTANDARD1_3 || NETSTANDARD1_6
            // Core
        #else
            // Full framework
        #endif
    }
    

    You can do:

    private TypeInfo GetTypeInfo(Type type)
    {
        #if NET_CORE
            // Core
        #else
            // Fullframework
        #endif
    }
    

    See here for more details on multi-targeting: Developing Libraries with Cross Platform Tools, How to Multitarget

提交回复
热议问题