.NET: with respect to AssemblyVersion, what defines binary compatibility?

喜夏-厌秋 提交于 2019-12-13 11:42:26

问题


What changes to a strong-named assembly necessitate a change in AssemblyVersionAttribute? Clearly, changing the public api in a way that could require a client to have to make a code change requires an increase in AssemblyVersion. But what about changes to the public API that don't require code changes in the client? For instance:

  • the addition of a public class or interface?
  • the addition of a public member to a public class or interface? (EDIT: drscroogemcduck correctly points out below that adding a member to an interface would hose all implementors. Silly me.)
  • an increase of visibility of a class member?

There's got to be definitive documentation of this somewhere on MSDN (or, knowing MS, on some MSSE's personal blog). But I simply cannot find it. Please help!


回答1:


It's pretty easy... as long as Types remain unchanged (in their public or protected layout) and method signatures are not changed (adding methods or types is fine), the JIT should be able to link the DLL just fine.

That said, I think that even if it does work you should not do this. Make a new version and use a policy to map the old version to the new one, if required. Otherwise you drive yourself straight back to DLL hell... and I'm pretty sure you don't want that.




回答2:


In response to Martijn's bounty:

The best reference on binary compatibility is on the community Wiki.

A definite guide to API-breaking changes in .NET




回答3:


adding methods to an interface shouldn't be fine because old providers won't implement the new methods.




回答4:


Microsoft adds new methods/classes in .NET libraries in service pack releases without changing AssemblyVersion (still 2.0.0.0 / 3.0.0.0). Microsoft only changes the AssemblyFileVersion. For example, In .NET 2.0 SP1, DateTimeOffset struct was added.

Should this practice be recommended to us because Microsoft do this? It is confusing.



来源:https://stackoverflow.com/questions/768832/net-with-respect-to-assemblyversion-what-defines-binary-compatibility

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!