在Linux系统中使用dotnet命令无法运行.NET应用的求助
Hey there, sorry to hear you hit this snag after initially getting your .NET console app up and running on Ubuntu 17.10.1! Let’s work through some troubleshooting steps to fix the "dotnet won’t run my app" issue:
1. First, double-check your .NET installation
Start by running this command to confirm your SDK and runtime are properly recognized:
dotnet --info
Look for entries like SDK Version: and Runtime Environment: — if either is missing or shows an unexpected version, your environment might be misconfigured.
If the SDK isn’t showing up, verify the dotnet path is in your PATH variable:
echo $PATH
You should see /usr/share/dotnet listed. If not, temporarily add it with:
export PATH=$PATH:/usr/share/dotnet
Then try running your app again. To make this change permanent, add that line to your ~/.bashrc or ~/.profile file and restart your terminal.
2. Clear project build cache
Corrupted build artifacts are a common culprit. Navigate back to your hwapp directory and delete the bin and obj folders:
cd hwapp rm -rf bin obj
Then rebuild and run the app:
dotnet run
3. Re-restore project dependencies
Sometimes NuGet packages get corrupted or fail to download properly. Run this to refresh your dependencies:
dotnet restore
Wait for it to complete, then try dotnet run again.
4. Test with a fresh project
To rule out issues with your original hwapp project, create a brand new console app and test it:
dotnet new console -o testapp cd testapp dotnet run
If this fresh app works, the problem is isolated to your original project. You can either compare the .csproj files for differences (like an incorrect TargetFramework value) or copy your code into the new project.
5. Reinstall the .NET SDK if all else fails
If none of the above works, your SDK installation might be damaged. First, uninstall the existing SDK:
sudo apt remove dotnet-sdk-<your-version> # Replace <your-version> with your installed SDK, e.g., 2.1 sudo apt autoremove sudo apt clean
Then re-install the compatible SDK (Ubuntu 17.10 supports .NET Core 2.x and 3.1; newer versions won’t work). Follow the official steps to add the Microsoft package source, then install the SDK again.
内容的提问来源于stack exchange,提问作者L. Page

