Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a .NET Standard DLL binary compatible with a .NET Framework one?

I currently have a utilities library built as .NET Framework 4.6.1 and referenced by various .NET Framework applications.

I now want to create a new .NET Core application and therefore I want to convert the utilities library to .NET Standard 2.0 so that it can be used by applications of both types.

If I simply open the source code for the library, change the target to .NET Standard 2.0 and rebuild it (assuming that it does only use APIs available in .NET Standard), can I just drop the new assembly in to replace the existing one and should the existing applications still work? Or would the applications need to be rebuilt against the new version?

And the more general related question is, what are the differences in the metadata produced for a .NET Standard DLL compared to a .NET Framework one, and how/if do they affect the assembly resolver?

(to pre-empt the comment "why not just try it and see", I want to know if this is a supported scenario, not just whether technically it might work for me)

like image 776
gallivantor Avatar asked Oct 25 '18 03:10

gallivantor


1 Answers

.Net Standard is a compatible cross-section between (but not limited to) .Net Framework and .Net Core

Think of it like this

enter image description here

Or, one of the more standard propaganda pictures

enter image description here

There are lot of things in .Net Framework that just doesn't make a lot of sense in .Net Core. Windows specific things for instance.

However, what you can do is use The .NET Portability Analyzer to work out any glaring compatibility problems

Want to make your libraries multi-platform? Want to see how much work is required to make your application compatible with other .NET implementations and profiles, including .NET Core, .NET Standard, UWP, and Xamarin for iOS, Android, and Mac? The .NET Portability Analyzer is a tool that provides you with a detailed report on how flexible your program is across .NET implementations by analyzing assemblies. The Portability Analyzer is offered as a Visual Studio Extension and as a console app.

And here is another picture (of the tool), because it makes my post look detailed

enter image description here

To answer your question

If I simply open the source code for the library, change the target to .NET Standard 2.0 and rebuild it, can I just drop the new assembly in to replace the existing one and should the existing applications still work? Or would the applications need to be rebuilt against the new version?

Needs to be rebuilt as far as i know, try it see what happens and let us know.

There are so many things that could make this not work.

And the more general related question is, what are the differences in the metadata produced for a .NET Standard DLL compared to a .NET Framework one, and how/if do they affect the assembly resolver?

Not entirely sure what you mean, however it will resolve just the same when rebuilt.

(to pre-empt the comment "why not just try it and see", I want to know if this is a supported scenario, not just whether technically it might work for me)

Just replacing the assembly is not supported as far as i know or could research. However maybe someone else has more information here.

like image 166
TheGeneral Avatar answered Oct 19 '22 00:10

TheGeneral