Reputation: 611
I have created a nuget package which supports both .net framework and .net core. But one class in it has references only available for .net core. I dnt need that class to be available in .net framwork
Is there any attribute or way is available, which exclude that class while building package for .net framweork?
This is how I am targetting frameworks
<TargetFrameworks>netcoreapp2.0;netstandard2.0;net45;net46</TargetFrameworks>
Upvotes: 3
Views: 2138
Reputation: 1499770
Just use the conditional compilation symbols that will be supplied automatically on a per-target basis. For example:
// Put this at the start of the file (if you want some of the file to still be built)
// or class (if you just want to exclude a single class). You could even
// exclude just a single method, or part of a method.
#if NETCOREAPP2_0 || NETSTANDARD2_0
public class NetFrameworkOnlyClass
{
}
// And this at the end
#endif
Or instead of including, you could exclude like this:
#if !NET45 && !NET46
See the cross-platform library tutorial for a list of conditional compilation symbols defined in each environment. (I think it would be nice to have version-neutral "NETCORE
", "NETSTANDARD
" and "NETFULL
" symbols or similar, but I don't believe those exist. You could specify them in your project file if you wanted to.)
Upvotes: 6