简体   繁体   中英

If I add a public method to a C# class, do I need to recompile other assemblies using that type?

Question in the title.

I'd like to avoid recompiling since the source code I'm modifying is third party and I'd like to use the original binaries where possible, and replace only the assembly which contains the class I modified. But I'm not sure if this is a safe thing to do. In C++ for example this is definitely a bad idea.

No.

The assemblies that reference your library refer to methods and types using (some form of) name, so as long as you don't change the names of public types and methods (used by other assemblies), you don't need to recompile any of the assemblies - they will work with the updated version of the library.

In most cases Tomas answer is correct, but there are some cases where it is not true:

  1. When using strong naming (signing) change of a single character leads to a new signature, thous leading to a new strong name.
  2. Setting in your project references for your assembly the property Specific Version to true and changing the version number manually or automatically in AssemblyInfo.cs

不会。所有其他程序集将自动使用新更新的库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM