You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Visual Studio Code创建C#项目?解决dotnet指令无响应问题

Hey there! Let's walk through both how to create a C# project in VS Code and fix that frustrating issue where dotnet new console does nothing at all.

How to Create a C# Project in Visual Studio Code

First, let’s cover the standard workflow (once your tools are working properly):

  • Make sure you have Visual Studio Code installed, plus the C# for Visual Studio Code (OmniSharp) extension from the marketplace.
  • Install a compatible .NET SDK (we’ll talk about version compatibility in the fix section below).
  • Create a new folder for your project, then open it in VS Code (File > Open Folder).
  • Open the integrated terminal (press `Ctrl + `` or go to View > Terminal).
  • Run dotnet new console – this generates the basic "Hello World" project structure (Program.cs, .csproj file, etc.).
  • To test it, run dotnet run – you should see "Hello World!" printed in the terminal.
Fixing the Unresponsive dotnet new console Command

If executing dotnet new console gives no output and no project files are created, here are the most common fixes to try:

1. Verify the .NET SDK is installed and in your PATH

First, check if your system recognizes the dotnet command at all. In the terminal, run:

dotnet --version
  • If this command also does nothing or throws a "not found" error, your SDK wasn’t added to your system’s PATH during installation.
    • On Windows: Go to System Properties > Advanced > Environment Variables, find the Path variable under System Variables, and add the path to your .NET SDK’s bin folder (usually C:\Program Files\dotnet\). Restart VS Code (and your terminal) after making changes.
    • On macOS/Linux: Check your shell config file (like ~/.bashrc or ~/.zshrc) to ensure the dotnet path is added. You can manually add it with export PATH="$PATH:/usr/local/share/dotnet" then restart your terminal/VS Code.
  • If dotnet --version returns your 2.1.10 version, move to the next step.

2. Check Folder Permissions

Sometimes the issue is just that your user account doesn’t have write access to the folder you’re working in:

  • On Windows: Try opening VS Code as an administrator (right-click VS Code > Run as administrator) then re-run the command.
  • On macOS/Linux: Run ls -ld /path/to/your/folder to check permissions. If needed, you can adjust permissions with chmod -R 755 /path/to/your/folder (or use sudo dotnet new console temporarily, though it’s better to fix folder permissions long-term).

3. Clear .NET Cache

Corrupted cache files can cause weird behavior. Run these commands in the terminal to clear them:

dotnet nuget locals all --clear

Wait for the process to finish, then try dotnet new console again.

4. Upgrade Your .NET SDK Version

.NET 2.1.10 is a very old release (it’s out of support now) and might have compatibility issues with newer versions of VS Code or the C# extension. Consider upgrading to a supported LTS (Long-Term Support) version like .NET 6 or .NET 8:

  • Uninstall the old 2.1.10 SDK from your system’s Apps & Features (Windows) or using your package manager (macOS/Linux).
  • Grab a supported LTS .NET SDK version, install it, and make sure the installation adds it to your PATH.
  • After installing, run dotnet --version to confirm the new version is recognized, then try creating the project again.

5. Test with the Full Path to dotnet

If all else fails, try running the command using the full path to the dotnet executable to rule out PATH issues:

  • On Windows:
    "C:\Program Files\dotnet\dotnet.exe" new console
    
  • On macOS/Linux:
    /usr/local/share/dotnet/dotnet new console
    

If this works, you know the problem is definitely with your PATH configuration.

Once you get the dotnet command responding, the rest of the project setup should be straightforward. Let me know if any of these steps get you up and running!

内容的提问来源于stack exchange,提问作者Alberto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:50:22