Mono编译C#项目报错CS0012:未引用Object定义的程序集求助
Alright, let's tackle this CS0012 error you're hitting. The issue boils down to one simple thing: when you're manually invoking csc with custom references, you're missing the core .NET assemblies that define basic types like Object—specifically System.dll and System.Core.dll.
Here are the steps to fix it:
Add core assembly references to your compile command
Modify yourcsccall to include-r:System.dlland-r:System.Core.dllright at the start. These are required for any C# code since they contain fundamental types your project depends on. Your updated command should look like this:csc -r:System.dll -r:System.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Commands.dll -r:./bin/Release/PublishOutput/Discord.Net.WebSocket.dll -r:./bin/Release/PublishOutput/RedditSharp.dll */*.csVerify Mono's core assembly path (if the first step fails)
If you still get the error, it might be becausecsccan't find the core assemblies. Check where Mono stores them using:find /usr/lib/mono -name System.dllYou'll get a path like
/usr/lib/mono/4.5/System.dll(the version number might vary based on your Mono installation). Add this directory to your command with the-lib:flag:csc -lib:/usr/lib/mono/4.5 -r:System.dll -r:System.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Core.dll ... */*.csUse
msbuildinstead of manualcsccalls (recommended)
Manually writingcsccommands is error-prone. If your project has a.csprojfile, let Mono's build system handle dependencies automatically:msbuild /p:Configuration=Release YourProjectName.csprojThis will automatically pull in all required core assemblies and your project's NuGet references, so you won't have to manually list every DLL.
The root cause here is that when you specify custom references with -r, csc doesn't automatically include the default core assemblies it normally would. Since Object is defined in System.dll, omitting that reference triggers the CS0012 error.
内容的提问来源于stack exchange,提问作者Tommy Muir

