You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio误删文件后仅存空C#窗体,能否反汇编旧Assembly获取源码?

Can I Recover Source Code by Decompiling the Assembly?

Absolutely! You can absolutely recover usable source code from the existing assembly that's still running—here's a straightforward guide to do it:

Step 1: Locate the Assembly File

  • When Visual Studio prompts you to open the previous assembly, note the file path shown in the dialog box. This will be your project's compiled .exe or .dll file.
  • If you missed the prompt, check your project's output directory (usually bin/Debug or bin/Release, depending on your build configuration) — that's where the compiled assembly lives.

Step 2: Use a .NET Decompiler

There are several reliable, free tools for decompiling .NET assemblies:

  • dnSpy: A powerful open-source tool that lets you not only decompile but also debug assemblies.
  • ILSpy: Another popular open-source decompiler with a clean, easy-to-navigate interface.
  • JetBrains dotPeek: A free tool from JetBrains that works standalone and integrates smoothly with their IDEs if you use them.

How to Use These Tools:

  • Launch the decompiler, then simply drag and drop your .exe/.dll file into the tool window.
  • Expand the assembly's structure to explore namespaces, classes, forms, and methods. You'll even find that the auto-generated form designer code (the content that lives in .Designer.cs files) is fully recoverable.

Important Notes

  • The decompiled code won't be identical to your original source:
    • Variable names might be simplified (e.g., submitButton could become var_001 if debug symbols weren't included in the build).
    • All comments will be gone — comments aren't stored in compiled assemblies, so they can't be recovered.
  • If your assembly was obfuscated, decompilation will be much harder. But since your project was working normally before deletion, it's unlikely to have been obfuscated.
  • Once you have the decompiled code, copy it into your empty project, clean up variable names, and re-organize as needed — most of your core logic and form layout will be intact.

Pro tip: Going forward, use a version control system like Git (even just a local repo) or enable Visual Studio's auto-backup features to avoid losing work like this again!

内容的提问来源于stack exchange,提问作者rec0rd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 20:03:12