2

I don't really understand those preprocessor directives what I have to write. I'm developing a library that should work for many frameworks e.g. .net framework 4.5, 4.6,... and for my application that runs with framework .NETStandard Version 1.5 -> so I guess this is dnxcore50?

public class MyClass
{
#if DOTNET5_4
    // do nothing
#else
    public void MyMethod()
    {
        Console.WriteLine("framework is supported");
        // and do anything with libraries available in the framework :)
    }
#endif
}

so this is what I got for now, but MyMethod is not available with any other framework. Using #if DOTNETCORE50 doesn't work, too.

I also tried to define constraints but my project fails to load when I try this.

Any idea what's the right solution?

8
  • Related : stackoverflow.com/questions/3436526/… Commented Jul 22, 2016 at 19:08
  • @x... i tried this already but after changing my solution-file, the project always fails loading. Commented Jul 22, 2016 at 19:10
  • Not solution file, project file. You edit the wrong file. Commented Jul 22, 2016 at 23:49
  • The information you got, such as DNX and NETCORE50, is out of date. Everything changes when Mocrosoft ships .NET Core 1.0 last month, so you have to start all over again at dot.net . And the sad news is that things are changing again, if you check the latest roadmap at .NET Blog. Commented Jul 23, 2016 at 1:16
  • 1
    @MatthiasBurger it is the very first time for Microsoft to develop a brand new platform in the wide open way, so we can observe the twists and turns (used to be their internal chats). So I think such changes are in all not a bad things, as it leads to more awareness (though confusion too). For most developers, they should wait till this fall's Visual Studio release, which completes the tooling, and fills the gaps. Commented Jul 25, 2016 at 6:57

1 Answer 1

3

There's no need to define them in project/solution-file anymore.

So, I just post an answer matching the current state (a few are still missing like net47 and so on, but you know what I mean):

#if (NET45 || NET451 || NET46 || NET461)
#define NetFramework
#endif

#if (NETSTANDARD1_0 || NETSTANDARD2_0 || NETSTANDARD1_5 || NETSTANDARD1_3 || NETSTANDARD1_6 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP2_0)
#define NetCore
#endif

in what way they are now compatible or redundant, I dont' know. But this is the current names I know.

then you can

public class MyClass
{

#if NetFramework
    public void MyMethod()
    {
        Console.WriteLine("framework is supported");
        // and do anything with libraries available in the framework :)
    }
#endif

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.