dot net core build platform/os specific code or class files

前端 未结 1 1715
半阙折子戏
半阙折子戏 2021-01-18 13:42

I want to build a .net core library that will have platform specific code for doing win32 and osx calls and when compiling the library for each target os, I want to include

相关标签:
1条回答
  • 2021-01-18 13:58

    You could define a build definition in your project.json

    "buildOptions": {
                    "define": [ "PORTABLE328" ]
                }
    

    eg:

    {
        "frameworks":{
            "netstandard1.6":{
               "dependencies":{
                    "NETStandard.Library":"1.6.0",
                }
            },
            ".NETPortable,Version=v4.0,Profile=Profile328":{
                "buildOptions": {
                    "define": [ "PORTABLE328" ]
                },
                "frameworkAssemblies":{
                    "mscorlib":"",
                    "System":"",
                    "System.Core":"",
                    "System.Net"
                }
            }
        }
    }
    

    Now you can conditionally compile against that target:

    #if !PORTABLE328
    using System.Net.Http;
    using System.Threading.Tasks;
    // Potentially other namespaces which aren't compatible with Profile 328
    #endif
    

    Source

    0 讨论(0)
提交回复
热议问题