질문)
WSL에서 c# 프로젝트 생성및 코드실행
답변)
>WSL에서 [sudo apt install -y dotnet-sdk-8.0] 설치 모습
WSL(예: Ubuntu) 환경에서 dotnet 명령어가 없어서 콘솔 앱을 만들 수 없다는 메시지입니다. 해결을 위해서는 WSL 내에 .NET SDK를 설치해야 합니다.
✅ 해결 방법: WSL에 .NET 8 SDK 설치하기
아래는 Ubuntu WSL 환경에서 .NET 8 SDK를 설치하는 절차입니다.
🔧 1. Microsoft 패키지 저장소 등록
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb |
⚠️ 위의 명령어는 Ubuntu 22.04 기준입니다. lsb_release -a 명령어로 Ubuntu 버전을 먼저 확인해보세요.
🔧 2. 필수 패키지 업데이트 및 설치
sudo apt update sudo apt install -y dotnet-sdk-8.0 |
🔍 3. 설치 확인
결과:
이제 dotnet new console -o RECV 명령이 정상 동작할 것입니다.
⛔️ 참고: apt install dotnet-host-8.0 만 설치하면 안 되는 이유
- dotnet-host는 실행을 위한 런타임만 설치하고, dotnet new, dotnet build 등 개발 명령은 사용할 수 없습니다.
- dotnet-sdk-8.0 패키지를 설치해야 SDK 전체 기능을 쓸 수 있습니다.
🔄 WSL에서 자주 쓰는 .NET 명령
dotnet new console -o MyApp # 새 콘솔 프로젝트 생성 cd MyApp dotnet run # 실행 dotnet build # 빌드 |
프로젝트 코드 실행예제)
1. TCP/IP 수신프로그램 프로젝트 생성
root@DESKTOP-QNNUCER:/mnt/c/Users/B210145_BK/ubuntu/distributed# dotnet new console -o RECV Welcome to .NET 8.0! --------------------- SDK Version: 8.0.412 Telemetry --------- The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry ---------------- Installed an ASP.NET Core HTTPS development certificate. To trust the certificate, view the instructions: https://aka.ms/dotnet-https-linux ---------------- Write your first app: https://aka.ms/dotnet-hello-world Find out what's new: https://aka.ms/dotnet-whats-new Explore documentation: https://aka.ms/dotnet-docs Report issues and find source on GitHub: https://github.com/dotnet/core Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli -------------------------------------------------------------------------------------- The template "Console App" was created successfully. Processing post-creation actions... Restoring /mnt/c/Users/B210145_BK/ubuntu/distributed/RECV/RECV.csproj: Determining projects to restore... Restored /mnt/c/Users/B210145_BK/ubuntu/distributed/RECV/RECV.csproj (in 120 ms). Restore succeeded. root@DESKTOP-QNNUCER:/mnt/c/Users/B210145_BK/ubuntu/distributed# |
2. TCP/IP 송신프로그램 프로젝트 생성
root@DESKTOP-QNNUCER:/mnt/c/Users/B210145_BK/ubuntu/distributed# dotnet new console -o SEND The template "Console App" was created successfully. Processing post-creation actions... Restoring /mnt/c/Users/B210145_BK/ubuntu/distributed/SEND/SEND.csproj: Determining projects to restore... Restored /mnt/c/Users/B210145_BK/ubuntu/distributed/SEND/SEND.csproj (in 117 ms). Restore succeeded. root@DESKTOP-QNNUCER:/mnt/c/Users/B210145_BK/ubuntu/distributed/SEND# ls -lrt total 0 -rwxrwxrwx 1 root root 252 Jul 18 11:10 SEND.csproj -rwxrwxrwx 1 root root 105 Jul 18 11:10 Program.cs drwxrwxrwx 1 root root 512 Jul 18 11:10 obj root@DESKTOP-QNNUCER:/mnt/c/Users/B210145_BK/ubuntu/distributed/SEND# |
WSL>RECV(수신)![]() |
WSL>SEND(송신) ![]() |
결론)
Windows에서의 결과와 똑같은 결과를 나타냄을 알수 있다.
'리눅스 > Windows' 카테고리의 다른 글
Windows에서 WSL(Windows Subsystem for Linux) 을 설정 (0) | 2025.07.18 |
---|---|
윈도우 11로 자동 업그레이드되지 않도록 설정하려면(?) (0) | 2025.01.24 |
CPU와 GPU의 역할 차이 (0) | 2024.11.07 |