官方版

Build Extension Assemblies for Fiddler v2 and v4

  • If you want your extension Assembly to run in both Fiddler2 and Fiddler4, build it for .NET Framework v2 and avoid taking any dependencies on any classes that were removed or moved in the later version of the Framework. (The only instance I’m aware of is the Microsoft JScript.NET code compiler, whose classes were moved around a bit).
    You’ll also need to ensure that if you use any methods that are deprecated (for example, calling Assembly.LoadFrom with the overload that takes an Evidence parameter) you do so only conditionally. For example:

    1. if (CONFIG.bRunningOnCLRv4)
    2. {
    3. a = Assembly.LoadFrom(oFile.FullName);
    4. }
    5. else
    6. {
    7. a = Assembly.LoadFrom(oFile.FullName, evidenceFiddler);
    8. }
  • All of the extensions from the Fiddler website are compiled against Fiddler v2.

  • Alternatively, you can simply build two versions of your DLL, one version targeting .NET Framework v4 and one targeting .NET Framework v2.
    This is how Fiddler itself is built. Basically, just add a “clone” version of your v2-targeted Project to the same Solution. Use the Add > Existing Item context menu to add the .CS files from the v2-targeted project to the v4-targeted project, but when selecting the files, be very sure to use the split button on the file picker dialog and choose Add as Link. On the v4 Project’s Properties > Build tab, add a Conditional Compilation symbol like DOTNET4. You can then put any .NETv4-specific code behind conditional compilation:

    1. #if DOTNET4
    2. // ... code targeting .NETv4
    3. #else
    4. // ... code targeting .NETv2
    5. #endif

    Your extension may install the appropriately-targeted version based on the content of the InstalledVersion registry key found inside:

    1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fiddler2
  • The .NET2 version of Fiddler is much more popular than the .NETv4 version at this time. When the .NET Framework v4.5 is released, I may move the v4 project over to v4.5. Among other things, that would allow me to take advantage of the new built-in .ZIP classes in that later framework.

  • What about the RequiredVersion attribute?
    Fiddler v4 is “smart”— if your extension specifies
    1. [assembly: Fiddler.RequiredVersion("2.1.0.1")]
    When Fiddler v4 loads it, it will require version 4.3.9.9 or later.

谷歌翻译版

为Fiddler v2 和 v4构建扩展程序集

  • 如果要使扩展程序集在Fiddler2和Fiddler4中运行,请为.NET Framework v2生成扩展程序集,并避免依赖于在更高版本的Framework中删除或移动的任何类. (我所知道的唯一实例是微软的JScript。NET代码编译器,它的类被移动了一些)。您还需要确保,如果使用任何不建议使用的方法(例如,使用带有Evidence参数的重载调用Assembly.LoadFrom),则只能有条件地这样做。 例如:

    1. if (CONFIG.bRunningOnCLRv4)
    2. {
    3. a = Assembly.LoadFrom(oFile.FullName);
    4. }
    5. else
    6. {
    7. a = Assembly.LoadFrom(oFile.FullName, evidenceFiddler);
    8. }
  • Fiddler网站上的所有扩展都是针对Fiddler v2编译的。

  • 或者,您可以简单地构建DLL的两个版本,一个针对.NET Framework v4,一个针对.NET Framework v2。这就是Fiddler本身的构建方式。 基本上,只需将针对v2的项目的“克隆”版本添加到同一解决方案中。 Use the Add > Existing Item context menu to add the .CS files from the v2-targeted project to the v4-targeted project, but when selecting the files, be very sure to use the split button on the file picker dialog and choose Add as Link. On the v4 Project’s Properties > Build tab, add a Conditional Compilation symbol like DOTNET4. You can then put any .NETv4-specific code behind conditional compilation:

    1. #if DOTNET4
    2. // ... code targeting .NETv4
    3. #else
    4. // ... code targeting .NETv2
    5. #endif

    你的扩展可以安装适当的目标版本基于内容的InstalledVersion注册表有关键

    1. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fiddler2
  • Fiddler的.NET2版本目前比.NETv4版本更受欢迎。 当.NET Framework v4.5发布时,我可能会将v4项目移至v4.5。 除其他事项外,这将使我能够利用该更高版本框架中的新内置.ZIP类。

  • 那么RequiredVersion属性呢?
    Fiddler v4 is “smart”— if your extension specifies
    1. [assembly: Fiddler.RequiredVersion("2.1.0.1")]
    当Fiddler v4加载它时,它需要4.3.9.9或更高版本。