Ubuntu下使用Rider创建C#项目及System引用异常问题求助
Hey there, let’s work through this problem together—it’s super common when both Mono and the .NET SDK are installed side-by-side, and Rider ends up picking the wrong MSBuild toolchain. Here’s a step-by-step breakdown to get your C# console app running smoothly:
1. Ensure Rider uses the .NET SDK's MSBuild
First, we need to confirm Rider isn’t defaulting to Mono’s MSBuild:
- Open Rider and go to Settings/Preferences (File → Settings on Windows/Linux, Rider → Preferences on macOS)
- Navigate to Build, Execution, Deployment → Build Tools → MSBuild
- Look for the list of detected MSBuild instances. Select the one labeled "dotnet-msbuild" (it should point to your .NET SDK installation path, e.g.,
/usr/local/share/dotnet/sdk/7.0.400/MSBuild.dllorC:\Program Files\dotnet\sdk\7.0.400\MSBuild.dll) - Uncheck any Mono-based MSBuild entries if they’re selected, then apply the changes.
2. Clear project and Rider caches
Stale caches often cause reference resolution issues:
- In Rider, go to File → Invalidate Caches...
- Select the option to "Invalidate and Restart"
- While Rider is restarting, manually delete the
bin,obj, and.ideafolders from your project directory (these will get recreated fresh when you reopen the project)
3. Verify your project's .csproj configuration
Double-check your project file to make sure it’s targeting a modern .NET runtime, not a Mono-specific framework:
- Open your project’s
.csprojfile in Rider - Ensure the
<TargetFramework>element specifies a .NET SDK version you have installed, like:<TargetFramework>net6.0</TargetFramework> - Remove any lines that force Mono usage, such as
<UseMonoMSBuild>true</UseMonoMSBuild>if present.
4. Validate your .NET SDK setup outside Rider
Let’s rule out issues with your .NET installation itself:
- Open a terminal/command prompt and run
dotnet --version—this should return a valid version number (e.g.,7.0.400) - Navigate to your project directory and run
dotnet build. If this completes successfully, the problem is definitely with Rider’s configuration (go back to step 1 to recheck MSBuild selection) - Ensure your system’s
PATHenvironment variable lists the .NET SDK directory before any Mono directories. This ensures tools likedotnettake priority over Mono equivalents.
5. Reset Rider's MSBuild detection (last resort)
If none of the above works, reset Rider’s MSBuild tool detection:
- Close Rider completely
- Locate Rider’s configuration directory:
- Windows:
%APPDATA%\JetBrains\Rider<your-version> - macOS:
~/Library/Application Support/JetBrains/Rider<your-version> - Linux:
~/.config/JetBrains/Rider<your-version>
- Windows:
- Delete the
msbuildfolder inside this directory - Reopen Rider—it will re-scan your system for MSBuild tools, and you can reselect the dotnet-msbuild instance as in step 1.
If you still run into issues after these steps, feel free to share more details about your OS, .NET/Mono versions, and any specific error messages from the build output.
内容的提问来源于stack exchange,提问作者brainbuggged

