Support changing C# nullable references context build option
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -23,6 +23,32 @@ namespace Flax.Build.NativeCpp
|
||||
GenerateProject = 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The nullable context type used with reference types (C#).
|
||||
/// </summary>
|
||||
public enum CSharpNullableReferences
|
||||
{
|
||||
/// <summary>
|
||||
/// The code is nullable oblivious, nullable warnings and language analysis features are disabled.
|
||||
/// </summary>
|
||||
Disable,
|
||||
|
||||
/// <summary>
|
||||
/// The compiler enables all null reference analysis and all language features.
|
||||
/// </summary>
|
||||
Enable,
|
||||
|
||||
/// <summary>
|
||||
/// The compiler performs all null analysis and emits warnings when code might dereference null.
|
||||
/// </summary>
|
||||
Warnings,
|
||||
|
||||
/// <summary>
|
||||
/// The compiler doesn't perform null analysis or emit warnings when code might dereference null.
|
||||
/// </summary>
|
||||
Annotations,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The native C++ module build settings container.
|
||||
/// </summary>
|
||||
@@ -188,6 +214,15 @@ namespace Flax.Build.NativeCpp
|
||||
/// </summary>
|
||||
public bool IgnoreMissingDocumentationWarnings;
|
||||
|
||||
/// <summary>
|
||||
/// The nullable context used in C# project.
|
||||
/// </summary>
|
||||
public CSharpNullableReferences CSharpNullableReferences = CSharpNullableReferences.Disable;
|
||||
|
||||
public ScriptingAPIOptions()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the other options into this.
|
||||
/// </summary>
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
|
||||
csProjectFileContent.AppendLine(" <TargetFramework>net7.0</TargetFramework>");
|
||||
csProjectFileContent.AppendLine(" <ImplicitUsings>disable</ImplicitUsings>");
|
||||
csProjectFileContent.AppendLine(" <Nullable>annotations</Nullable>");
|
||||
csProjectFileContent.AppendLine(string.Format(" <Nullable>{0}</Nullable>", baseConfiguration.TargetBuildOptions.ScriptingAPI.CSharpNullableReferences.ToString().ToLowerInvariant()));
|
||||
csProjectFileContent.AppendLine(" <IsPackable>false</IsPackable>");
|
||||
csProjectFileContent.AppendLine(" <EnableDefaultItems>false</EnableDefaultItems>");
|
||||
csProjectFileContent.AppendLine(" <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>");
|
||||
|
||||
Reference in New Issue
Block a user