VSCode搭建 .netcore 开发环境

一、MacOS

笔者笔记本电脑上安装的是macOS High Sierra(10.13),想要尝试一下新版本的.netcore,之前系统是10.12时,.netcore 3.1刚出来时安装过3.1版本,很久没更新了,最近.net8出来了,想试一下,但是需要更新系统,于是安装了.netcore7,它的支持时间到2024年5月14日。

下载了.netcore7后,直接双击安装即可。安装后的路径为:/usr/local/share/dotnet

笔者VSCode的版本为1.85.1,需要安装C#插件,目前最新版本为2.14.8,但macOS 10.13目前最高只能安装v1.26.0版本的C#插件,不能安装更高的版本,否则不能调试。

另外还需要安装一个.NET Install Tool插件:

这样就可以在终端使用dotnet命令创建项目了,比如创建一个控制台应用:

shell 复制代码
$ dotnet new console
已成功创建模板"控制台应用"。

正在处理创建后操作...
正在还原 /Users/witton/Projects/cc/cc.csproj:
  正在确定要还原的项目...
  已还原 /Users/witton/Projects/cc/cc.csproj (用时 120 ms)。
已成功还原。

此时打开生成的Program.cs,并打上断点,切换到运行和调试工具栏,执行Generate C# Assets for Build and Debug,插件会自动生成launch.jsontasks.json两个文件:


launch.json

json 复制代码
{
	"version": "0.2.0",
	"configurations": [
		{
			// Use IntelliSense to find out which attributes exist for C# debugging
			// Use hover for the description of the existing attributes
			// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
			"name": ".NET Core Launch (console)",
			"type": "coreclr",
			"request": "launch",
			"preLaunchTask": "build",
			// If you have changed target frameworks, make sure to update the program path.
			"program": "${workspaceFolder}/bin/Debug/net7.0/cc.dll",
			"args": [],
			"cwd": "${workspaceFolder}",
			// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
			"console": "internalConsole",
			"stopAtEntry": false
		},
		{
			"name": ".NET Core Attach",
			"type": "coreclr",
			"request": "attach"
		}
	]
}

tasks.json:

json 复制代码
{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "build",
			"command": "dotnet",
			"type": "process",
			"args": [
				"build",
				"${workspaceFolder}/cc.csproj",
				"/property:GenerateFullPaths=true",
				"/consoleloggerparameters:NoSummary"
			],
			"problemMatcher": "$msCompile"
		},
		{
			"label": "publish",
			"command": "dotnet",
			"type": "process",
			"args": [
				"publish",
				"${workspaceFolder}/cc.csproj",
				"/property:GenerateFullPaths=true",
				"/consoleloggerparameters:NoSummary"
			],
			"problemMatcher": "$msCompile"
		},
		{
			"label": "watch",
			"command": "dotnet",
			"type": "process",
			"args": [
				"watch",
				"run",
				"--project",
				"${workspaceFolder}/cc.csproj"
			],
			"problemMatcher": "$msCompile"
		}
	]
}

此时按F5运行启动调试即可开始调试C#程序:

微软开发了一个新的插件C# Dev Kit,它提供了更加强大的功能,并且可以像VS那样使用解决方案资源管理器来管理项目。该插件需要C#插件为2.0及以上版本,但由于笔者的MacOS系统比较老了,C#插件2.0及以上版本不能进行调试,所以只能使用1.X来将就使用了。

如果是macOS 10.15及以上版本,就可以直接安装.net8了,VSCode插件也可以直接安装C# Dev Kit以及IntelliCode for C# Dev Kit插件了。但是由于.NET Install Tool插件目前仅支持7.x版本的.net,所以还需要安装.net 7runtime:runtime-7.0.14-macos-x64-installer

安装好后就可以使用F1调出.NET:新建项目...命令,来新建.net项目了:

选择项目模板:

比如选择控制台应用,创建好项目后,可以看到解决方案资源管理器

二、Windows

如果是Windows10,则可以直接安装最新的.net 8,并且安装上C# Dev Kit以及IntelliCode for C# Dev Kit,也不需要 像macOS那样还需要安装.net 7runtime

相关推荐
magic334165634 小时前
ESP32S3开发环境介绍和创建工程
vscode·c·头文件
萌萌站起5 小时前
Vscode 中 python模块的导入问题
ide·vscode·python
aqiu~5 小时前
VSCode编辑器用于Unity项目
vscode·unity
csdn_aspnet12 小时前
在 .NET Core 8 中实现 CORS
.netcore·跨域·cors·.net8
ZXF_H14 小时前
VSCode C/C++函数Ctrl+鼠标点击无法跳转的解决方法
c++·ide·vscode
linux_map15 小时前
大模型微调实战指南
人工智能·python·ai·策略模式
zhangfeng113317 小时前
vscode 之类的编辑器 ,跳转到某一个函数 方法 是什么快捷键 this->getEbayReturns($shop);
ide·vscode·编辑器
ShawnLiaoking17 小时前
vscode 配置环境
ide·vscode·编辑器
弈风千秋万古愁17 小时前
vscode使用markdown+plantuml
vscode·markdown·plantuml
日更嵌入式的打工仔19 小时前
Visual Studio 与 Visual Studio Code 区别
ide·vscode