Home > Net >  Why can't I include RestSharp in my Unity project?
Why can't I include RestSharp in my Unity project?

Time:03-16

I'm trying to use the code given by Postman to connect an API to my Unity project. The code uses RestSharp. I regenerated Embeded packages and Local packages project files. link to Unity/Preferences/External Tools/Generate .csproj files for: then installed RestSharp version 107.3.0 using NuGet package manager extension on Visual Studio Code. Then used dotnet restore because NuGet told me to. Now my "Assembly-CSharp.csproj" file has:

<PackageReference Include="RestSharp" Version="107.3.0"/>

But still, whenever I try to add:

using RestSharp;

line to my APITest.cs script, Unity says:

APITest.cs(4,7): error CS0246: The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?)

What can I do to use RestSharp with Unity?

CodePudding user response:

You can't add projects to Unity via NuGet. Any changes to a .csproj file inside Unity will get overwritten the next time Unity auto-generates it. Unity doesn't actually use those .csproj files the same way a "normal" C# installation does -- it just generates them so that IDEs have an easier time understanding the code.

There are several different ways to add a package to a Unity project:

  • Related