mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 05:31:01 +00:00 
			
		
		
		
	 9b24d5f2d0
			
		
	
	
		9b24d5f2d0
		
	
	
	
	
		
			
			Allow game projects to use a Godot.NET.Sdk with a newer patch version. The major and minor version are still required to be the same. For example: Allow a Godot 3.2.4 C# project to use a hypothetical 3.2.5 version of Godot.NET.Sdk.
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.IO;
 | |
| using System.Text;
 | |
| using Microsoft.Build.Construction;
 | |
| using Microsoft.Build.Evaluation;
 | |
| 
 | |
| namespace GodotTools.ProjectEditor
 | |
| {
 | |
|     public static class ProjectGenerator
 | |
|     {
 | |
|         public const string GodotSdkVersionToUse = "3.2.3";
 | |
|         public const string GodotSdkNameToUse = "Godot.NET.Sdk";
 | |
| 
 | |
|         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 = $"{GodotSdkNameToUse}/{GodotSdkVersionToUse}";
 | |
| 
 | |
|             var mainGroup = root.AddPropertyGroup();
 | |
|             mainGroup.AddProperty("TargetFramework", "net472");
 | |
| 
 | |
|             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().ToUpper();
 | |
|         }
 | |
|     }
 | |
| }
 |