diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs
index 921a1e43f..e6a250eb5 100644
--- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs
+++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Flax.Build.Graph;
+using Flax.Build.NativeCpp;
using Flax.Deploy;
namespace Flax.Build
@@ -242,7 +243,9 @@ namespace Flax.Build
args.Add("/filealign:512");
#if USE_NETCORE
args.Add("/langversion:11.0");
- args.Add("-nowarn:8632"); // Nullable
+ args.Add(string.Format("/nullable:{0}", buildOptions.ScriptingAPI.CSharpNullableReferences.ToString().ToLowerInvariant()));
+ if (buildOptions.ScriptingAPI.CSharpNullableReferences == CSharpNullableReferences.Disable)
+ args.Add("-nowarn:8632"); // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
#else
args.Add("/langversion:7.3");
#endif
diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs
index 8a5a55873..c2ea81372 100644
--- a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs
+++ b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs
@@ -23,6 +23,32 @@ namespace Flax.Build.NativeCpp
GenerateProject = 1,
}
+ ///
+ /// The nullable context type used with reference types (C#).
+ ///
+ public enum CSharpNullableReferences
+ {
+ ///
+ /// The code is nullable oblivious, nullable warnings and language analysis features are disabled.
+ ///
+ Disable,
+
+ ///
+ /// The compiler enables all null reference analysis and all language features.
+ ///
+ Enable,
+
+ ///
+ /// The compiler performs all null analysis and emits warnings when code might dereference null.
+ ///
+ Warnings,
+
+ ///
+ /// The compiler doesn't perform null analysis or emit warnings when code might dereference null.
+ ///
+ Annotations,
+ }
+
///
/// The native C++ module build settings container.
///
@@ -188,6 +214,15 @@ namespace Flax.Build.NativeCpp
///
public bool IgnoreMissingDocumentationWarnings;
+ ///
+ /// The nullable context used in C# project.
+ ///
+ public CSharpNullableReferences CSharpNullableReferences = CSharpNullableReferences.Disable;
+
+ public ScriptingAPIOptions()
+ {
+ }
+
///
/// Adds the other options into this.
///
diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs
index ed8222fb7..efce04776 100644
--- a/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs
+++ b/Source/Tools/Flax.Build/Projects/VisualStudio/CSSDKProjectGenerator.cs
@@ -88,7 +88,7 @@ namespace Flax.Build.Projects.VisualStudio
csProjectFileContent.AppendLine(" net7.0");
csProjectFileContent.AppendLine(" disable");
- csProjectFileContent.AppendLine(" annotations");
+ csProjectFileContent.AppendLine(string.Format(" {0}", baseConfiguration.TargetBuildOptions.ScriptingAPI.CSharpNullableReferences.ToString().ToLowerInvariant()));
csProjectFileContent.AppendLine(" false");
csProjectFileContent.AppendLine(" false");
csProjectFileContent.AppendLine(" false");