Use detected .NET and C# language version in generated project files

This commit is contained in:
2023-11-26 20:26:53 +02:00
parent 0bcd0154e1
commit aab88a746d
2 changed files with 15 additions and 2 deletions

View File

@@ -161,6 +161,18 @@ namespace Flax.Build
/// </summary>
public readonly string RuntimeVersionName;
/// <summary>
/// Maximum supported C#-language version for the SDK.
/// </summary>
public string CSharpLanguageVersion => Version.Major switch
{
8 => "12.0",
7 => "11.0",
6 => "10.0",
5 => "9.0",
_ => "7.3",
};
/// <summary>
/// Initializes a new instance of the <see cref="DotNetSdk"/> class.
/// </summary>

View File

@@ -28,6 +28,7 @@ namespace Flax.Build.Projects.VisualStudio
/// <inheritdoc />
public override void GenerateProject(Project project, string solutionPath)
{
var dotnetSdk = DotNetSdk.Instance;
var csProjectFileContent = new StringBuilder();
var vsProject = (VisualStudioProject)project;
@@ -96,7 +97,7 @@ namespace Flax.Build.Projects.VisualStudio
var cacheProjectsPath = Utilities.MakePathRelativeTo(Path.Combine(Globals.Root, "Cache", "Projects"), projectDirectory);
var flaxBuildTargetsPath = !string.IsNullOrEmpty(cacheProjectsPath) ? Path.Combine(cacheProjectsPath, flaxBuildTargetsFilename) : flaxBuildTargetsFilename;
csProjectFileContent.AppendLine(" <TargetFramework>net7.0</TargetFramework>");
csProjectFileContent.AppendLine($" <TargetFramework>net{dotnetSdk.Version.Major}.{dotnetSdk.Version.Minor}</TargetFramework>");
csProjectFileContent.AppendLine(" <ImplicitUsings>disable</ImplicitUsings>");
csProjectFileContent.AppendLine(string.Format(" <Nullable>{0}</Nullable>", baseConfiguration.TargetBuildOptions.ScriptingAPI.CSharpNullableReferences.ToString().ToLowerInvariant()));
csProjectFileContent.AppendLine(" <IsPackable>false</IsPackable>");
@@ -108,7 +109,7 @@ namespace Flax.Build.Projects.VisualStudio
csProjectFileContent.AppendLine(" <ProduceReferenceAssembly>false</ProduceReferenceAssembly>");
csProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", project.BaseName));
csProjectFileContent.AppendLine(string.Format(" <AssemblyName>{0}.CSharp</AssemblyName>", project.BaseName));
csProjectFileContent.AppendLine(" <LangVersion>11.0</LangVersion>");
csProjectFileContent.AppendLine($" <LangVersion>{dotnetSdk.CSharpLanguageVersion}</LangVersion>");
csProjectFileContent.AppendLine(" <FileAlignment>512</FileAlignment>");
//csProjectFileContent.AppendLine(" <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>"); // TODO: use it to reduce burden of framework libs