Skip to content

Commit ca4c0c8

Browse files
committed
Add documentation for common C# project file management tasks
1 parent ecdfcf8 commit ca4c0c8

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

manual/scripting/csharp/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Visit **[C# API Reference](../../../api-csharp/index.md)** to learn about script
44

55
## In this section
66

7+
* [Project file management](project-file-management.md)
78
* [Nuget Packages](nuget-packages.md)
89
* [Restrictions](restrictions.md)
910

1011
## How to create C# script?
1112

12-
C# scripting is enabled by default in [Flax Project modules](../../editor/flax-build/index.md), so C# scripts can be added without any further setup. In the *Content Window*, go to your project's module source folder `Source/<module_name>` and *right-click* to add **C# Script** in the module.
13+
C# scripting is enabled by default in [Flax Project modules](../../editor/flax-build/index.md), so C# scripts can be added without any further setup. In the *Content Window*, go to your project's module source folder `Source/<module_name>` and *right-click* to add **C# Script** in the module.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
```

manual/scripting/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ To start visual scripting see the related documentation [here](visual/index.md).
6060
* [Attributes](custom-editors/attributes.md)
6161
* [Preprocessor variables](preprocessor.md)
6262
* [C# Scripting](csharp/index.md)
63+
* [Project file management](csharp/project-file-management.md)
6364
* [Nuget Packages](csharp/nuget-packages.md)
6465
* [Scripting Restrictions](csharp/restrictions.md)
6566
* [C++ Scripting](cpp/index.md)

manual/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
### [Attributes](scripting/custom-editors/attributes.md)
189189
## [Preprocessor variables](scripting/preprocessor.md)
190190
## [C# Scripting](scripting/charp/index.md)
191+
### [Project file management](scripting/csharp/project-file-management.md)
191192
### [Nuget Packages](scripting/csharp/nuget-packages.md)
192193
### [Scripting Restrictions](scripting/csharp/restrictions.md)
193194
## [C++ Scripting](scripting/cpp/index.md)

0 commit comments

Comments
 (0)