0

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?

KiiVoZin
  • 15
  • 6
  • `installed RestSharp version 107.3.0 using NuGet package manager extension on Visual Studio Code` I would say that is why. Rather use e.g. [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) and install it there which makes sure it is actually installed into your Unity project as a [Plugin](https://docs.unity3d.com/Manual/Plugins.html) – derHugo Mar 15 '22 at 15:15

1 Answers1

1

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:

Jan
  • 848
  • 7
  • 17
  • Thanks to you, I've made RestSharp work by following this tutorial: https://www.youtube.com/watch?v=GRn49ehm_pI&ab_channel=MohammadFaizanKhan – KiiVoZin Mar 16 '22 at 10:37