Search code examples
c#macoshomebrewsdl-2rider

SDL2-CS on Mac M2 in Rider MAUI not found when using 'using' in C#


I've had issues for a while now with reading a joystick/controller using SDL2 in C#.

I am using SDL2 for cross platform dev using MAUI for Mac and Windows

I tried to install SDL2 using brew: brew install sdl2 which installed successfully. Then I installed SDL-CS using NuGet, both in terminal and in the Rider NuGet Section, I checked and it is loaded into my csproj file already, yet the following code would return errors when building: using SDL2; When I built I would simply get this error:

0>JoystickPage.xaml.cs(1,7): Error CS0246 : The type or namespace name 'SDL2' could not be found (are you missing a using directive or an assembly reference?)
0>------- Finished building project: InfiniteConnect. Succeeded: False. Errors: 1. Warnings: 0

This is on minimal Verbose logging and diagnostics did not even say why, just that the build failed with one error.

I have tried to add lines into my csproj such as:


    <ItemGroup>
        <NativeLibrary Include="/opt/homebrew/opt/sdl2/lib/libSDL2.dylib" />
    </ItemGroup>
    <ItemGroup>
        <None Update="/opt/homebrew/opt/sdl2/lib/libSDL2.dylib">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

But again nothing worked, I attempted other things but also nothing, maybe I am not doing it right.

brew --prefix sdl2

simply returns the correct directory:

/opt/homebrew/opt/sdl2

I added DYLD_LIBRARY_PATH=/opt/homebrew/opt/sdl2/lib:$DYLD_LIBRARY_PATH to environment variables in maccatalyst which is what I am using to run with.

Am I missing something? I restarted Rider and cleaned and rebuilt every time.

EDIT: Here is where I target the libraries;

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="SDL2-CS" Version="2.0.0" />
    </ItemGroup>

Solution

  • You're still missing relevant information (specifically, what complete .Net framework you're binding against), but if we assume that you're using .Net Core then the package you want is SDL2-CS.NetCore:

    enter image description here

    Whereas SDL2-CS runs against the legacy .Net Framework:

    enter image description here