Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is like this I want a Project A which has func say Foo() which returns NETSTANDARD or NETFRAMEWORK depending on which type it is. Another Project B calls Foo() from its function Bar() and returns the result it gets I want this code to be capable of returning either strings

What I have tried:

public static string FooImpl()
{
#if NETSTANDARD2_0
return "NETSTANDARD";
#elif NET461
return "NETFRAMEWORK";
#endif
}
Posted
Updated 17-Dec-17 0:01am

1 solution

string dotNetClass = "";
string dotNet = dotNetClass.GetType().Assembly.FullName;


This gives ""mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
 
Share this answer
 
Comments
Member 13580583 17-Dec-17 6:09am    
This is not what I am looking for.
Please see my code and you will get the idea of what I expect.
________________ 17-Dec-17 6:17am    
Have a look at https://www.codeproject.com/Articles/827091/Csharp-Attributes-in-minutes

.NET has modern tools (not just preprocessor). If you need to calculate something on compilation stage - use attributes.
Member 13580583 17-Dec-17 6:29am    
Thanks for the help but my requirement is not that complex it is a simple program which if compiled in net standard(Or a compilation symbol is defined) returns NETSTANDARD and if in Net Framework it returns NETFRAMEWORK.
I understand attributes but I still prefere #ifdefs.
Member 13580583 17-Dec-17 6:34am    
If a project type is Net Standard library you get a pre defined compilation symbol NETSTANDARD2_0 in your project properties.
________________ 17-Dec-17 6:58am    
Compiler need case if nothing defined:

public static string FooImpl()
{
#if NETSTANDARD2_0
return "NETSTANDARD";
#elif NET461
return "NETFRAMEWORK";
#endif
return "";
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900