使用Mono mcs编译C#项目时找不到Graph与Solver类的问题排查
sudokuColour.Graph and sudokuColour.Solver Types Hey there, let's break down why you're hitting those CS0246 errors with the mcs compiler when your code runs flawlessly in Visual Studio 2015. The root difference lies in how each tool handles compilation scope:
The Core Problem
Visual Studio automatically manages all source files in your project. When you build, it compiles Program.cs alongside the files that define Graph and Solver (like Graph.cs and Solver.cs under the sudokuColour namespace) without you having to explicitly list them.
The mcs command-line compiler doesn't do this auto-detection. If you only run a command like:
mcs Program.cs
It only processes Program.cs and has no awareness of the other files that contain the sudokuColour.Graph and sudokuColour.Solver types. That's exactly why it throws the "type or namespace not found" errors.
Fixes to Try
You need to explicitly tell mcs to include all dependent source files during compilation. Here are straightforward ways to do this:
List each file directly: If your
GraphandSolverclasses are in separate files (either in the same directory asProgram.csor asudokuColoursubfolder), run:# For files in the same directory mcs Program.cs Graph.cs Solver.cs # For files in a sudokuColour subfolder mcs Program.cs sudokuColour/Graph.cs sudokuColour/Solver.csUse wildcards for bulk files: If you have multiple files in the namespace, wildcards can save you typing:
# Compile all .cs files in the root directory and sudokuColour folder mcs *.cs sudokuColour/*.cs
Quick Sanity Checks
Just to rule out edge cases:
- Double-check that the
sudokuColournamespace spelling (including capitalization) matches exactly across all files. VS is case-insensitive on Windows, but mcs (a cross-platform compiler) enforces case sensitivity. - Ensure
GraphandSolverhave an accessible modifier. Since they're in the same namespace, the defaultinternalaccess works fine—if you'd set them toprivate, VS would have thrown an error too, so this is unlikely.
内容的提问来源于stack exchange,提问作者Mats Nyström

