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
.exeor.dllfile. - If you missed the prompt, check your project's output directory (usually
bin/Debugorbin/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/.dllfile 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.csfiles) is fully recoverable.
Important Notes
- The decompiled code won't be identical to your original source:
- Variable names might be simplified (e.g.,
submitButtoncould becomevar_001if 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.
- Variable names might be simplified (e.g.,
- 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
相关产品推荐
相关产品推荐

