0

I'm a beginner to C#, working on macOS at the CLI. (I do not have access to IDEs for everyday development; I can use one occasionally for a one-off command, but that's it.)

I'm attempting to add the Krafs.Rimworld.Ref package from NuGet to my project; this provides, amongst other things, a namespace Verse.

This project has to be a .NET Framework 4.7.2 project (this, too, I have no control over); thus, I've installed Mono, since I develop on macOS.

My .csproj (complete) has the following in it:

<PackageReference Include="Krafs.Rimworld.Ref">
  <Version>1.3.3087</Version>
</PackageReference>

When I navigated to the folder of the solution containing that .csproj and run dotnet restore, it didn't print any useful information; only the following:

❯ HelloCSharp main* dotnet restore
  Determining projects to restore...
  All projects are up-to-date for restore.

The instructions for compiling that I'm following offer the following advice on how to build:

FrameworkPathOverride="$(dirname $(which mono))/../lib/mono/4.7.2-api/" \
  dotnet build Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj /property:Configuration=Release

Unfortunately, it's still complaining about the Verse namespace from that ref-only NuGet package missing:

Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(2,7): error CS0246: The type or namespace name 'Verse' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(7,6): error CS0246: The type or namespace name 'StaticConstructorOnStartupAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(7,6): error CS0246: The type or namespace name 'StaticConstructorOnStartup' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]

Build FAILED.

Checking ~/.nuget/packages, there is indeed a krafs.rimworld.ref/1.3.3087/ref/net472/Assembly-CSharp.dll downloaded. ILSpy shows it contains the required Verse namespace and refs. I just can't figure out why the above dotnet build command can't find those refs, despite the PackageReference in the .csproj.

(All of this works fine when done through the GUI on Windows, because of course it does. The issues I'm having are only on macOS / Mono / at the CLI.)

ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
  • This [answer](https://stackoverflow.com/a/43541864/1901309) might be of help – freeAll Aug 14 '21 at 18:05
  • You can't build a .NET 4.x project on a Mac, that's Windows only. – DavidG Aug 14 '21 at 18:15
  • That's what the Mono is for, @DavidG — I'm having no problems building 4.7.2 projects *except* regarding the package-reference issue described above. – ELLIOTTCABLE Aug 14 '21 at 18:22
  • You shouldn't use `FrameworkPathOverride` now, as Microsoft proposed a much better option, https://github.com/Microsoft/dotnet/tree/master/releases/reference-assemblies BTW, what version of .NET Core SDK are you using? `dotnet --info` should tell that. – Lex Li Aug 15 '21 at 01:59

1 Answers1

0

So, it's not a solution that I like, because it doesn't explain why the error is occuring — but I was able to bypass this issue, at least for the moment, by using the version of msbuild that ships with Mono:

msbuild HelloCSharpSolution.sln -restore -p:Configuration=Release

(This concerns me, as it means I'm stepping outside the sanctioned dotnet tooling; and losing any other behaviour that dotnet build may include that msbuild does not … so I'm leaving this question open in the hopes that someone can come up with a better explanation.)

ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78