本文最后更新于(2023-1-20 10:41:18),链接可能失效,内容可能难以复现。请注意甄别。
© Sunplace,2017
引言
Visual Studio Code是相对于Visual Studio更轻量的程序,如果不想用动则5、6G的Visual Studio,可以试试这个。
1.下载安装Visual Studio Code。
Windows版的大小约为32.4M:
2.安装C#扩展。
打开VS Code之后搜索C#,下载这个:
3. 安装.NET Core(Command line / other)。
4. 打开VS Code,打开集成终端(Ctrl+`或“查看”-“集成终端”)。
5.创建项目文件夹(d:\test)并在集成终端中输入以下命令。
>cd d:\test D:\test>dotnet new显示:
Welcome to .NET Core! ——————— Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet –help to see available commands or go to https://aka.ms/dotnet-cli-docs. Telemetry ————– The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and sh ared with the community. You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell. You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry. Configuring… ——————- A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will onl y happen once. Decompressing 100% 3713 ms Expanding 100% 30901 ms Created new C# project in D:\test.
6.在项目文件夹下生成了Program.cs和project.json两个文件。
7.用VS Code打开Program.cs,看到以下内容:
using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }你可以重新编写或者修改此文件。 8.编译程序,在集成终端中输入:
D:\test>dotnet restore提示:
log : Restoring packages for d:\test\project.json… log : Writing lock file to disk. Path: d:\test\project.lock.json log : d:\test\project.json log : Restore completed in 8063ms.
9.接着运行,
d:\test>dotnet run提示:
Project test (.NETCoreApp,Version=v1.1) will be compiled because expected outputs are missing Compiling test for .NETCoreApp,Version=v1.1 Compilation succeeded. 0 Warning(s) 0 Error(s) Time elapsed 00:00:04.5183046 Hello World!
https://code.visualstudio.com/docs/runtimes/dotnet