Jump to content

Recommended Posts

Posted (edited)

I wanted to make a tutorial that is a little different from what is currently offered on the wiki (https://wiki.gtanet.work/index.php?title=Setting_Up_a_Development_Environment_using_Visual_Studio)

This tutorial gets you through setting up a project outside the RAGE MP folder, that automatically builds into a resource folder, and allows debugging by simply pressing "Run" or F5 in Visual Studio 2017

There's a download of a project set up this way in the bottom of the post, if you just want to get started as fast as possible. You'll need to change all the paths in the configured project obviously, but there you go.

Prerequisites

  • Visual Studio 2017 (At the time of writing, using version 15.7.1)
  • RAGE MP installed and server set up.
  • Common sense

 

Setup

Ensure the  .NET Core cross-platform development package/product is installed.

  1. Open Visual Studio Installer from the start menu
    ZK2W2FL.png
  2. Click on modify under Visual Studio {Version} 2017
    Ir8wHVp.png
  3. Find .NET Core cross-platform development and make sure it's checked
    jopeHxK.png
  4. If it wasn't installed previously, after checking the box on this item, click modify in the bottom right, and install the package.

 

Creating the project

  1. Open Visual Studio, and click File -> New -> Project.
  2. In the tree on the left, go to Installed -> Visual C# -> .NET Core. Then select Class Library (.NET Core) in the list on the right.
    Give your project a name in the bottom, choose a location to store it (can be anywhere on your PC), and hit OK
    CZhI5g9.png
  3. This should create a project that compiles as .NET Core 2.0, which is the version used for resources at the time of writing. It may change to 2.1 in version 0.4 of RAGE MP. To ensure the project compiles to Core 2.0, right click on your new project in the Solution Explorer, and select Properties.
    Under Target framework, ensure it says .NET Core 2.0
    uWWGNdg.png
  4. While we're here, we can configure debugging. On the left, select the Debug tab, change the Launch dropdown to Executable.
    A new item appears: Executable with a Browse... button. Click browse, and select your
    RAGE MP server.exe
    The second input below that is for Working directory, set that to the folder that contains server.exe
    UnMW21T.png
  5. Save this window and close it.

 

Build configuration

Now we need to change how the project is built. If you want use external NuGet packages, you'll want Visual Studio to copy their DLLs to the build directory.

  1. Right click on your project in the Solution Explorer, and click Edit {project name}.csproj
    zxuCU21.png
  2. Under 
    <TargetFramework>netcoreapp2.0</TargetFramework>

    Add the following:
     

    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

    8BcgXiD.png

  3. Save and close the file.

Now we set up the Meta.xml file.

  1. Right click on your project, and select Add -> New Item...
  2. In the pop-up dialog, click on Installed -> Visual C# Items in the tree on the left, then scroll down and select Xml File in the list on the right, and name it meta.xml
    jWJjFeU.png
  3. Replace the file contents with the following, replacing ExampleResource with the name of your project:
    <meta>
    	<info name="ExampleResource" type="script" />
    	<script src="ExampleResource.dll" />
    </meta>
  4. Save and close the file.
  5. Right click on the file in Solution Explorer and click Properties
  6. Set Build Action to Content and Copy to Output Directory to Copy always
    TuJAJmu.png

Now let's configure it to copy the built project to the resources directory.

  1. Go back to the project properties (Solution Explorer, right click on the project, Properties).
  2. Open the Build Events tab, and put the following code in the text box under Post-build event command line:
    del "D:\Games\RAGEMP\server-files\bridge\resources\ExampleResource\*.*" /Q
    xcopy "$(OutDir)*" "D:\Games\RAGEMP\server-files\bridge\resources\ExampleResource" /Y

    Make sure to replace the path to \bridge\resources and ExampleResource with the correct path to the resources, and your project name. Also make sure the folder exists, obviously.
    mol6zoL.png

  3. Save and close the properties window.

Try going to Build -> Rebuild Solution in the top of Visual Studio. This should complete successfully, and several DLLs should now appear in the resource folder in your server installation.

 

Add the resource to the server settings.xml

  1. Open the settings.xml file in the RAGE MP server directory under the bridge folder
  2. Add the following, replacing ExampleResource with the name of your resource
    <resource src="ExampleResource" />
    SstPReh.png
  3. Save and close the file.

 

Creating the resource

Alright, that should be the basic project and debugging configured. Now let's add the GTA Network package so we can create a resource.

  1. In the Solution Explorer, right click on your project and select Manage NuGet packages...
    6t9Tynu.png
  2. Click on Browse in the top left, search for gtanetwork.api, and install the gtanetwork.api package.
    0yja7aR.png
  3. By default, there should be a Class1.cs with a class in it called Class1. I like to rename this to Main.cs with a class Main, I suggest you do the same as I'll be referring to it in the rest of the tutorial.
  4. Replace the content of the file with the following. I will not be explaining basic C#, but it'll demonstrate the project working, and give you an entry point for the code:
    using System;
    using GTANetworkAPI;
    
    namespace ExampleResource
    {
    	public class Main : Script
    	{
    		[ServerEvent(Event.ResourceStart)]
    		public void OnResourceStart()
    		{
    			NAPI.Util.ConsoleOutput("Example resource loaded!");
    		}
    	}
    }

     

  5. Save the file, and HIT THAT MF DEBUG BUTTON in the top of Visual Studio xLl2vzq.png

The server should now start up and show our console output:

YKSidaP.png

 

Breakpoints

Breakpoints should also work immediately, try placing one on the console output, and hit debug:

rNteXru.png

 

If something still doesn't work, you can download an example project here, which was set up using the steps above. Obviously you'll need to change the paths configured in it to match your system, but it may help you debug any issues.

Edited by Eraknelo
  • Like 17
Posted (edited)
Quote

Try going to Build -> Rebuild Solution in the top of Visual Studio. This should complete successfully, and several DLLs should now appear in the resource folder in your server installation.

This step failed for me because ExampleResource folder doesn't exists,

So I have created one but It said copied 0 files and it is empty after rebuild

What am I doing wrong?

EDIT: Never mind. I was placing the commands in pre-build instead of post build!! Sorry!

Edited by FailerZ
  • Like 1
  • 3 weeks later...
Posted (edited)
37 minutes ago, Illuminated said:

Hello,

i have a problem like this:

Picture KLICK

 

What i´m doing wrong ?!

Is the path correct?

Make sure to replace the path to \bridge\resources and ExampleResource with the correct path to the resources, and your project name.

Edited by Eraknelo
Posted
15 minutes ago, Illuminated said:

yes, I have tried it with my own project and with the sample project, always the same mistake.

 

So you're saying that you actually happen to have the exact folder in the exact same place on your system? D:\Games\RAGEMP\server-files\bridge\resources\ExampleResource\ is an existing folder?

Posted (edited)

 

vor 4 Minuten schrieb Eraknelo:

So you're saying that you actually happen to have the exact folder in the exact same place on your system? D:\Games\RAGEMP\server-files\bridge\resources\ExampleResource\ is an existing folder?

yes, to be exact, I changed the paths to D:\RAGEMP\server-files\bridge\resources\PROJECTANAME\ . it does not work anyway. Now I've tried it with JetBrains Rider, there it goes = P

Edited by Illuminated
Guest Sоukyan
Posted
1 minute ago, Illuminated said:

 

yes, to be exact, I changed the paths to D:\RAGEMP\server-files\bridge\resources\PROJECTANAME\ . it does not work anyway. Now I've tried it with JetBrains Rider, there it goes = P

Provide whole post build event code.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...