How add a external dll to use it in our c# scripts?

Hello everybody,

I have done a first script in C# by following the car spawner tutorial which work perfectly.
In my Visual Studio solution I have a project for this car spawner named “Operator” and I have another one where I would develop the database service named “Database”. I wanted to use this database service in the actual car spawner project.

In the Database project I just created a static method which return a string “hello world”.

In the Operator project, I added a reference on the Database project and I trigger a chat message which call the static method of database service to display “Hello word” in the chat.

But when I call the command to display the message, the program can’t find the Database.dll.
I tried to :

  • put this dll near to the Operator.net.dll
  • put the dll in the FXServer\server directory
    but the issue is still here.

Could you tell me how should I do to make it work please ?

thanks !

ok I found how to do this thanks to Loading/finding nuget package dll files alongside a server script

So you have to put the .dll file in your current ressources mods directory and add in the fxmanisfest.lua it relative path in the "file category.

image

image

Don’t ever interact with a server database via the client :worried:

1 Like

Of course d0p3t :slight_smile:
I’m just learning how thing work on fiveM, I don’t want a file named TestScript.cs as well :stuck_out_tongue:

Please remember server scripts don’t have to be specified in “file” (otherwise they will be downloaded by clients?).

Clients can (potentially) extract .dll files and then decompile so be careful what you put here

I’m not sure to understand how it works.

The files added in the files { … } section will be downloaded on the client ? That what you are saying ?

[edit] yes it is https://docs.fivem.net/docs/scripting-reference/resource-manifest/resource-manifest/

i saw the server_only key word. Do you know should I use it ?

thanks for the comment and the help

server_only means “send nothing to clients”, implying you have no client_script for that ressource

If you want your secret_server_only.dll stay on server, don’t specify it in fxmanifest (secret_server_only.dll contain sensitive info as db password or is an external dll (eg: mysql))
Note If secret_server_only.dll is a FiveM server ressources, specify it in server_script

“external dll” like NewtonsoftJson, NativeUI might be used in your client_script so they have to be in “files”

If you use secret_server_only.dll in your client_script, it must be in “file” too BUT it won’t be secret because it will be sent to clients

1 Like

thank a lot Less. I understand how to sort my stuff now.
Since DB is server only, the dll file will only be mentioned in the server_script.

My first test-script was developed as client script so my test confused me about that.

A really appreciate comments like yours and d0p3t. That shows a dev community that takes care about others project. :slight_smile:

1 Like