Scripting in C#
Setting up our environment
Before you can create your first C# resource, you’ll need to install Visual Studio 2022 (the community/free version will work just fine).
Creating your project
- Open a command window by pressing
Win + R, you should have a console like the one below:
- Once that window shows up we’re going to be following the FiveM’s Cookbook modern guide to setup our scripting environment, so make sure you enter the following commands in the console window:
dotnet new -i CitizenFX.Templates mkdir MyResource cd MyResource dotnet new cfx-resource
- If everything went right, you should get a folder named
MyResourcewith a solution file named
MyResource.sln. This is the solution file to manage your projects.
- To build the project, you can click on
build.cmd, which will build a release server and client dll for you, both targetting the correct
.NET Frameworkneeded for FiveM.
Setting up and running the project
If you built the resource, you should now have a
dist folder available, so you should be able to run the following commands:
Change directory to the resource path named
cd /d [PATH TO THIS RESOURCE]
Make a symbolic link. For more information about
mklink, visit the following article by Microsoft.
mklink /d X:\cfx-server-data\resources\[local]\MyResource dist
Afterwards, you can use
ensure MyResource in your
server.cfg or server console to start the resource.
Congratulations, you’ve created a resource using FiveM’s C# templates!