简体   繁体   English

如果我向C#类添加一个公共方法,我是否需要使用该类型重新编译其他程序集?

[英]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. 以C ++为例,这绝对是一个坏主意。

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: 在大多数情况下,Tomas的答案是正确的,但有些情况并非如此:

  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 在程序集的项目引用中设置属性Specific Version为true并在AssemblyInfo.cs中手动或自动更改版本号

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要使用C#将组合框传递给类方法 - I need to pass a combobox to a class method using C# C#卫星程序集? 我是否需要链接默认的文化资源 - C# Satellite Assemblies? Do I need to link default culture resource 如何重新编译 C# 程序以在 ARM CPU 上运行? - How do I recompile C# programs to run on ARM CPUs? 在 Visual Studio 2019 中,如何将我的项目程序集(或任何程序集)添加到 C# 交互式窗格? - In Visual Studio 2019, how do I add my project assemblies (or any assemblies at all) to the C# interactive pane? 我可以在C#中使用不同的类型初始化类的公共属性吗? - Can I initialize public properties of a class using a different type in C#? 如何将参数传递给C#中的公共类? - How do I pass arguments to a public class in C#? 为什么我可以在C#中执行此操作?(带有()的公共类 - Why can i do this in C#?(public class with ()) 如何在不创建该类的新对象的情况下调用其他类的方法? C# - How do I call a method of an other class without creating a new object of the class? c# 在 C# 中,如何在方法中创建一个 object 并将其添加到其他对象的列表中? - In C#, how do i create an object within a method and add it to a list of other objects? 为什么我需要在C#中使用局部类和虚方法? - why i need partial class and virtual method in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM