Setting Up a Development Environment on Windows

From GTA Network Wiki
Jump to: navigation, search

Setting up a development environment with Visual Studio

VisualStudio.png

If you're going to be developing in C# a lot, it's preferable if you set up a solution with projects. This gives a lot of benefits, the most important one of those is autocompletion.

This page will explain how to set it up in a way that you don't have to compile your projects to dll's, and still work swiftly and productively.

Visual Studio

Which version of Visual Studio will you be using? You can use any, but since GTA Network runs on .Net 4.0, you should at least be using 2010. You can download Visual Studio for free here.

Creating the solution

Let's start by creating our solution. The theory behind this method of setting up Visual Studio is that the "resources" folder is essentially our Visual Studio solution folder.

Start by going to File -> New -> Project, and find "Blank Solution" in the project types. In Visual Studio 2015 (and above), this is likely under Templates -> Other Project Types -> Visual Studio Solutions.

Set the name of the solution to just "resources", and the location to where you have your GTANServer installed.

VisualStudio1.png

Once you click OK, a new "resources.sln" is created in your resources folder and the empty solution will be opened in Visual Studio.

Creating a new resource

When you decide to create a new resource, all you have to do in Visual Studio is right click on the solution in the solution explorer, then Add -> New Project. You will then have to find the "Class Library (.NET Framework)" project template and enter a name. The project name you enter in this dialog will be your resource name, so if you wanted to make a cool gamemode called "Epic Stunts" you will probably want to enter "epicstunts" or "epic-stunts" here.

When you click OK, your project will be created and the folder for your resource is also created. You will still have to manually add and maintain a meta.xml for the resource. You can do this either outside of Visual Studio, or inside of Visual Studio by right clicking the project, Add -> New Item, and find "XML File". Give it the name "meta.xml" and then put your meta.xml content there.

Don't forget that when you add files to your project via Visual Studio, you have to manually add them to the meta.xml file.

To get autocompletion to work, you will have to add (to each resource/project you create) references the GTA Network API. To do this, right click "References" in the solution explorer for your project, and click "Manage NuGet Packages". In the search bar, search for "gtanetwork.api". It should give you a result from the GTA Network Dev Team. Click on the item, and click Install on the right side, and you're done!

Nuget1.png

Setting up an existing resource

If you already have a resource that you would like to add to Visual Studio, the process is very similar as above, except when you try to create a project when a folder already exists, you will get this error:

VisualStudio3.png

To work around this, I suggest you temporarily rename your existing folder (for example from "testing" to "testing-temp"), then create the project by the process explained above, and then manually move your files from the temp folder to the new folder. You can then simply drag your files that you moved to the folder into your project.

And that's it! You are now ready to start developing resources with Visual Studio.

Optional TypeScript autocompletion

If you want to have autocompletion for client side scripts, you can also do that in Visual Studio. You can simply write JavaScript files in Visual Studio, which will give you some basic autocompletion for your own functions and variables, but you don't get the complete API autocompletion. The best way to get the full autocompletion is to use Eraknelo's TypeScript definitions. (Note that you can simply write JavaScript in TypeScript files as well, so you don't necessarily need to learn TypeScript.)

In Visual Studio, this will result in intellisense like this, for clientside scripting:

TypeScriptExample.png

To start, in the solution explorer for your project, right click on References -> Manage NuGet Packages. Under the Broswe tab, search for "gtanetwork". You should find this package:

Typescript1.png

Select it and click on Install. This will create a new folder "types-gtanetwork" in your project. These are the TypeScript definitions you will need for autocompletion.

Next, you will have to create a tsconfig.json file in your project root. This is the configuration that TypeScript will use to generate the actual JavaScript files that the client will be running. You can use this configuration: (You can tweak it of course, but make sure that compileOnSave is enabled.)

{
  "compilerOptions": {
    "alwaysStrict": true,
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": false,
    "target": "es6",
    "module": "commonjs"
  },
  "compileOnSave": true
}

You can then create a new TypeScript file (.ts) for your script. Note that the generated JavaScript file will have the same filename as the TypeScript filename, except with .js at the end instead of .ts. Once you have created your .ts file, add this line to the top of the file:

/// <reference path="types-gtanetwork/index.d.ts" />

And you're done. Now begin typing things like API. and witness the autocompletion. When you save the .ts file, a .js file will be generated if there were no TypeScript errors.

Optional automatic meta.xml generation

To increase speed of development, you may set up the automatic meta.xml generator external application. It will generate a meta.xml with all the files in the resource folder for you, every time a file changes.