1、建立项目文件夹Visual Studio Code没有建立项目的选项,需要自己建立文件夹。
此处将文件夹命名为:GoProject
2、Visual Studio Code中打开文件夹 3、新建代码文件
设置代码文件名称,注意后续必须为.go
编写go代码,按照惯例,第一份代码必需hello world
4、运行代码使用快捷键Ctrl+F5直接运行,第一次运行时我的环境提示了一个错误:
Starting: C:Users94225gobindlv-dap.exe dap --listen=127.0.0.1:53808 from d:zhaoxiGoProject DAP server listening at: 127.0.0.1:53808 Build Error: go build -o d:zhaoxiGoProject__debug_bin.exe -gcflags all=-N -l . go: go.mod file not found in current directory or any parent directory; see 'go help modules' (exit status 1)
此时需要使用终端命令行,输入指令go mod init XXX,XXX代表项目文件夹名称:
可以看到项目文件夹中自动生成了go.mod文件:
然后重新运行代码,可以看到已经正确运行并输出了hello world。



