c# - What's the best way to target multiple versions of the .NET framework? -
i'm building class library , deploy nuget package, lets me choose different assemblies added references based on .net framework version of project it's added to. nice feature, i'm wondering whether possible have single class library project, , build against mulitple versions of .net framework?
i'd rather avoid having:
mylibrary40.dll
, mylibrary45.dll
if possible, because 2 projects have share lot of code. 4.5 version offering async
functions, 4.5 feature.
does know best approach is? can use multiple build configurations? or must go down separate project route?
if working in c++ i'd use multiple configurations , #if
blocks around functions supported in 1 configuration, worry lead me having 2 assemblies same name different things.
thanks in advance!
you @ least need 1 visualstudio solution 2 projects (one .net 4 , 1 .net 4.5).
add codefiles .net 4-project , in other project add code files link (use "add existing item..."
-dialog , chose add link
)
now add codes , classes .net 4.5 4.5-project.
additionally should define own compiler switches (conditional compilation symbols) projects. net4 .net 4-project , net4.5 .net 4.5-project)
you set switches in project settings under build->general->conditional compilation switches
in code can use switches follows generate code .net 4 or .net 4.5
#if net4 // code .net 4 #endif // code framework versions. #if net45 // code .net 4.5 #endif
Comments
Post a Comment