软件研发 --- 如何开发不依赖net的exe
如果你的 Windows 系统没有安装 .NET Framework 或 .NET Core/5+/6+,你仍然可以通过以下方法编译生成可执行的 .exe 文件(不依赖 .NET 运行时):
1. 使用原生 Win32 API(C/C++)
适用语言:C、C++
工具链:MinGW、MSVC(Visual Studio 编译器)、Clang
特点:生成纯原生代码,无额外依赖
方法 1:MinGW(GCC for Windows)
-
安装 MinGW
-
编译 C 代码
// hello.c #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }编译命令:
gcc hello.c -o hello.exe
-
生成的
hello.exe可直接运行(无需 .NET)。
-
方法 2:MSVC(Visual Studio 编译器)
-
安装 Visual Studio Build Tools(无需完整 IDE)
-
勾选 “C++ 桌面开发” 组件
-
编译 C/C++ 代码
cl hello.c /Fe:hello.exe
-
生成的
.exe是原生 Win32 程序。
-
2. 使用 Go 语言
适用语言:Go
特点:静态编译,无外部依赖
-
安装 Go
-
编译 Go 代码
// hello.go package main import "fmt" func main() { fmt.Println("Hello, World!") }编译命令:
go build hello.go
-
生成
hello.exe,无需 Go 运行时即可运行。
-
3. 使用 Rust
适用语言:Rust
特点:内存安全,生成原生代码
-
安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
(或下载 Rust for Windows)
-
编译 Rust 代码
// main.rs fn main() { println!("Hello, World!"); }编译命令:
rustc main.rs
-
生成
main.exe,无需额外运行时。
-
4. 使用 Free Pascal(Delphi 替代方案)
适用语言:Pascal
特点:轻量级,生成原生代码
-
安装 Free Pascal
-
下载 Free Pascal
-
-
编译 Pascal 代码
// hello.pas program Hello; begin Writeln('Hello, World!'); end.编译命令:
fpc hello.pas
-
生成
hello.exe,无依赖。
-
5. 使用 V(Vlang)
适用语言:V
特点:极简语法,快速编译
-
安装 V
-
编译 V 代码
// hello.v fn main() { println("Hello, World!") }编译命令:
v hello.v
-
生成
hello.exe,无外部依赖。
-
6. 使用 Batch 转 EXE(仅简单脚本)
适用语言:Batch(.bat)
工具:Bat To Exe Converter
-
下载工具
-
转换
.bat到.exe-
打开
.bat文件 → 转换为.exe -
生成的
.exe仍依赖cmd.exe,但无需 .NET。
-
7. 使用 Python 转 EXE(需 Python 但无需 .NET)
适用语言:Python
工具:PyInstaller、Nuitka
-
安装 Python
-
编译 Python 脚本
pip install pyinstaller pyinstaller --onefile hello.py
-
生成
dist/hello.exe(包含 Python 运行时,但不依赖 .NET)。
-
8. 使用 Zig(新兴语言)
适用语言:Zig
特点:轻量级,可交叉编译
-
安装 Zig
-
编译 Zig 代码
// hello.zig pub fn main() void { @import("std").debug.print("Hello, World!\n", .{}); }编译命令:
zig build-exe hello.zig
浙公网安备 33010602011771号