简体   繁体   中英

Dotnet Core 3.1 & CSC: Predefined type 'System.Object' is not defined or imported

I have to extend an in-house build system to compile C# files targeting.Net Core 3.

As of now, the system is capable of processing source sets, references, and lib directories, where it generates the following command:

"C:\Program Files\dotnet\dotnet.exe" exec "C:/Program Files/dotnet/sdk/3.1.300/Roslyn/bincore/csc.dll" -nologo -target:library "-lib:C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4" -r:netstandard.dll C:/Users/kirsch/Documents/Repositories/ComplexProject/lib/csharp/native/VeryComplexLogic.cs -out:C:/Users/kirsch/Documents/Repositories/ComplexProject/default/ComplexProject.net.626a237a/ComplexProject.net.dll

Sadly, this fails with the following error:

error CS0518: Predefined type 'System.Object' is not defined or imported

I tried to search for a solution. The proposed solutions either suggested something, that was not related (like deleting some generated directory), or suggested to add references. Pursuing the latter, I added the following references:

  • netstandard.dll
  • mscorlib.dll
  • System.dll
  • System.Core.dll

Referencing these did, however, not solve the problem.

To conclude my question: Which reference am I missing?

If it's not a reference, what else am I missing then?

You need System.Runtime.dll .

Please note that just providing

/lib:"C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4"

is not enough. This is only a directory where the referenced assemblies will be searched for. But you still need to provide each particular referenced assembly by the /reference (or /r ) option:

/reference:mscorlib.dll /reference:netstandard.dll /reference:System.Collections.dll /reference:System.Console.dll

... etc

MSBuild or dotnet.exe do this for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM