|
| 1 | +# Project file management |
| 2 | + |
| 3 | +Flax.Build tool generates the required C# project files expected for the configured Code Editor, which usually uses the .csproj-file format accompanied with Visual Studio .sln-solution files. The code editor can then use these files to provide code completion and other features language server features to help the user navigate around the codebase. |
| 4 | + |
| 5 | +As these files are constantly regenerated after modifying the module files or adding new source files, any permanent modifications to the generated .csproj-file should be avoided. The expected place to do these modifications are in the [module configuration files](../../editor/flax-build/index.md) (eg. `Game.Build.cd`), which are used to configure the project file generation process. |
| 6 | + |
| 7 | +# Adding references |
| 8 | + |
| 9 | +`/Source/Game/MyScript.cs(32,13,32,18): error CS1069: The type name 'Regex' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.` |
| 10 | + |
| 11 | +When scripting requires referencing other common system references, we can modify the module build file (eg. `Game.Build.cd`) in the following way to add the reference to the required assembly: |
| 12 | +```cs |
| 13 | +public override void Setup(BuildOptions options) |
| 14 | +{ |
| 15 | + base.Setup(options); |
| 16 | + |
| 17 | + options.ScriptingAPI.SystemReferences.Add("System.Text.RegularExpressions"); |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +Referencing third-party C# library files can be done with file references, but in this case we need to provide the path to the assembly file: |
| 22 | +```cs |
| 23 | +public override void Setup(BuildOptions options) |
| 24 | +{ |
| 25 | + base.Setup(options); |
| 26 | + |
| 27 | + // Note: the path is relative to the .build file itself |
| 28 | + options.ScriptingAPI.FileReferences.Add(Path.Combine(FolderPath, "..", "..", "Content", "CustomAssembly.dll")); |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +In order to add **Nuget-packages** to your project, please see the dedicated section [here](nuget-packages.md). |
| 33 | + |
| 34 | +For a more thorough example to use third-party libraries can be found [here](../tutorials/use-third-party-library.html#using-c-library). |
| 35 | + |
| 36 | +# Analyzers and source generators |
| 37 | + |
| 38 | +Source generators and analyzers are also supported. System provided assemblies can be added in `SystemAnalyzers` and external file references to `Analyzers` lists: |
| 39 | +```cs |
| 40 | +public override void Setup(BuildOptions options) |
| 41 | +{ |
| 42 | + base.Setup(options); |
| 43 | + |
| 44 | + options.ScriptingAPI.SystemAnalyzers.Add("Microsoft.Interop.ComInterfaceGenerator"); |
| 45 | + |
| 46 | + // Note: the path is relative to the .build file itself |
| 47 | + options.ScriptingAPI.Analyzers.Add(Path.Combine(FolderPath, "..", "..", "Content", "CustomAnalyzer.dll")); |
| 48 | +} |
| 49 | +``` |
0 commit comments