mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 05:31:01 +00:00 
			
		
		
		
	 8d41b5a582
			
		
	
	
		8d41b5a582
		
			
		
	
	
	
	
		
			
			- Upgrades the TFM for new created projects to `net8.0`. - Implements system to upgrade TFM for existing projects to `net8.0`.
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Globalization;
 | |
| using System.IO;
 | |
| using System.Text;
 | |
| using Microsoft.Build.Construction;
 | |
| using Microsoft.Build.Evaluation;
 | |
| using GodotTools.Shared;
 | |
| 
 | |
| namespace GodotTools.ProjectEditor
 | |
| {
 | |
|     public static class ProjectGenerator
 | |
|     {
 | |
|         public static string GodotSdkAttrValue => $"Godot.NET.Sdk/{GeneratedGodotNupkgsVersions.GodotNETSdk}";
 | |
| 
 | |
|         public static string GodotMinimumRequiredTfm => "net8.0";
 | |
| 
 | |
|         public static ProjectRootElement GenGameProject(string name)
 | |
|         {
 | |
|             if (name.Length == 0)
 | |
|                 throw new ArgumentException("Project name is empty.", nameof(name));
 | |
| 
 | |
|             var root = ProjectRootElement.Create(NewProjectFileOptions.None);
 | |
| 
 | |
|             root.Sdk = GodotSdkAttrValue;
 | |
| 
 | |
|             var mainGroup = root.AddPropertyGroup();
 | |
|             mainGroup.AddProperty("TargetFramework", GodotMinimumRequiredTfm);
 | |
| 
 | |
|             mainGroup.AddProperty("EnableDynamicLoading", "true");
 | |
| 
 | |
|             string sanitizedName = IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true);
 | |
| 
 | |
|             // If the name is not a valid namespace, manually set RootNamespace to a sanitized one.
 | |
|             if (sanitizedName != name)
 | |
|                 mainGroup.AddProperty("RootNamespace", sanitizedName);
 | |
| 
 | |
|             return root;
 | |
|         }
 | |
| 
 | |
|         public static string GenAndSaveGameProject(string dir, string name)
 | |
|         {
 | |
|             if (name.Length == 0)
 | |
|                 throw new ArgumentException("Project name is empty.", nameof(name));
 | |
| 
 | |
|             string path = Path.Combine(dir, name + ".csproj");
 | |
| 
 | |
|             var root = GenGameProject(name);
 | |
| 
 | |
|             // Save (without BOM)
 | |
|             root.Save(path, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
 | |
| 
 | |
|             return Guid.NewGuid().ToString().ToUpperInvariant();
 | |
|         }
 | |
|     }
 | |
| }
 |