You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
C#: Replace uses of old Configuration and update old csprojs
(cherry picked from commit 1b634785b5)
This commit is contained in:
committed by
Rémi Verschelde
parent
b874e84147
commit
d46fcbb16a
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using DotNet.Globbing;
|
||||
using Microsoft.Build.Construction;
|
||||
|
||||
@@ -117,6 +118,7 @@ namespace GodotTools.ProjectEditor
|
||||
globOptions.Evaluation.CaseInsensitive = false;
|
||||
|
||||
var root = ProjectRootElement.Open(projectPath);
|
||||
Debug.Assert(root != null);
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups)
|
||||
{
|
||||
@@ -158,35 +160,35 @@ namespace GodotTools.ProjectEditor
|
||||
void AddPropertyIfNotPresent(string name, string condition, string value)
|
||||
{
|
||||
if (root.PropertyGroups
|
||||
.Any(g => (g.Condition == string.Empty || g.Condition == condition) &&
|
||||
.Any(g => (g.Condition == string.Empty || g.Condition.Trim() == condition) &&
|
||||
g.Properties
|
||||
.Any(p => p.Name == name &&
|
||||
p.Value == value &&
|
||||
(p.Condition == condition || g.Condition == condition))))
|
||||
(p.Condition.Trim() == condition || g.Condition.Trim() == condition))))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
root.AddProperty(name, value).Condition = condition;
|
||||
root.AddProperty(name, value).Condition = " " + condition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
||||
condition: " '$(Configuration)' != 'Release' ",
|
||||
condition: "'$(Configuration)' != 'ExportRelease'",
|
||||
value: "Debug");
|
||||
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
||||
condition: " '$(Configuration)' == 'Release' ",
|
||||
condition: "'$(Configuration)' == 'ExportRelease'",
|
||||
value: "Release");
|
||||
|
||||
void SetReferenceHintPath(string referenceName, string condition, string hintPath)
|
||||
{
|
||||
foreach (var itemGroup in root.ItemGroups.Where(g =>
|
||||
g.Condition == string.Empty || g.Condition == condition))
|
||||
g.Condition.Trim() == string.Empty || g.Condition.Trim() == condition))
|
||||
{
|
||||
var references = itemGroup.Items.Where(item =>
|
||||
item.ItemType == "Reference" &&
|
||||
item.Include == referenceName &&
|
||||
(item.Condition == condition || itemGroup.Condition == condition));
|
||||
(item.Condition.Trim() == condition || itemGroup.Condition.Trim() == condition));
|
||||
|
||||
var referencesWithHintPath = references.Where(reference =>
|
||||
reference.Metadata.Any(m => m.Name == "HintPath"));
|
||||
@@ -225,7 +227,7 @@ namespace GodotTools.ProjectEditor
|
||||
}
|
||||
|
||||
// Found no Reference item at all. Add it.
|
||||
root.AddItem("Reference", referenceName).Condition = condition;
|
||||
root.AddItem("Reference", referenceName).Condition = " " + condition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@@ -233,7 +235,7 @@ namespace GodotTools.ProjectEditor
|
||||
const string editorProjectName = "GodotSharpEditor";
|
||||
|
||||
const string coreCondition = "";
|
||||
const string editorCondition = " '$(Configuration)' == 'Tools' ";
|
||||
const string editorCondition = "'$(Configuration)' == 'Debug'";
|
||||
|
||||
var coreHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{coreProjectName}.dll";
|
||||
var editorHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{editorProjectName}.dll";
|
||||
@@ -241,6 +243,105 @@ namespace GodotTools.ProjectEditor
|
||||
SetReferenceHintPath(coreProjectName, coreCondition, coreHintPath);
|
||||
SetReferenceHintPath(editorProjectName, editorCondition, editorHintPath);
|
||||
|
||||
if (dirty)
|
||||
root.Save();
|
||||
}
|
||||
|
||||
public static void MigrateFromOldConfigNames(string projectPath)
|
||||
{
|
||||
var root = ProjectRootElement.Open(projectPath);
|
||||
Debug.Assert(root != null);
|
||||
|
||||
bool dirty = false;
|
||||
|
||||
bool hasGodotProjectGeneratorVersion = false;
|
||||
bool foundOldConfiguration = false;
|
||||
|
||||
foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition == string.Empty))
|
||||
{
|
||||
if (!hasGodotProjectGeneratorVersion && propertyGroup.Properties.Any(p => p.Name == "GodotProjectGeneratorVersion"))
|
||||
hasGodotProjectGeneratorVersion = true;
|
||||
|
||||
foreach (var configItem in propertyGroup.Properties
|
||||
.Where(p => p.Condition.Trim() == "'$(Configuration)' == ''" && p.Value == "Tools"))
|
||||
{
|
||||
configItem.Value = "Debug";
|
||||
foundOldConfiguration = true;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasGodotProjectGeneratorVersion)
|
||||
{
|
||||
root.PropertyGroups.First(g => g.Condition == string.Empty)?
|
||||
.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (!foundOldConfiguration)
|
||||
{
|
||||
var toolsConditions = new[]
|
||||
{
|
||||
"'$(Configuration)|$(Platform)' == 'Tools|AnyCPU'",
|
||||
"'$(Configuration)|$(Platform)' != 'Tools|AnyCPU'",
|
||||
"'$(Configuration)' == 'Tools'",
|
||||
"'$(Configuration)' != 'Tools'"
|
||||
};
|
||||
|
||||
foundOldConfiguration = root.PropertyGroups
|
||||
.Any(g => toolsConditions.Any(c => c == g.Condition.Trim()));
|
||||
}
|
||||
|
||||
if (foundOldConfiguration)
|
||||
{
|
||||
void MigrateConfigurationConditions(string oldConfiguration, string newConfiguration)
|
||||
{
|
||||
void MigrateConditions(string oldCondition, string newCondition)
|
||||
{
|
||||
foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition.Trim() == oldCondition))
|
||||
{
|
||||
propertyGroup.Condition = " " + newCondition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
foreach (var propertyGroup in root.PropertyGroups)
|
||||
{
|
||||
foreach (var prop in propertyGroup.Properties.Where(p => p.Condition.Trim() == oldCondition))
|
||||
{
|
||||
prop.Condition = " " + newCondition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups.Where(g => g.Condition.Trim() == oldCondition))
|
||||
{
|
||||
itemGroup.Condition = " " + newCondition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups)
|
||||
{
|
||||
foreach (var item in itemGroup.Items.Where(item => item.Condition.Trim() == oldCondition))
|
||||
{
|
||||
item.Condition = " " + newCondition + " ";
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var op in new[] {"==", "!="})
|
||||
{
|
||||
MigrateConditions($"'$(Configuration)|$(Platform)' {op} '{oldConfiguration}|AnyCPU'", $"'$(Configuration)|$(Platform)' {op} '{newConfiguration}|AnyCPU'");
|
||||
MigrateConditions($"'$(Configuration)' {op} '{oldConfiguration}'", $"'$(Configuration)' {op} '{newConfiguration}'");
|
||||
}
|
||||
}
|
||||
|
||||
MigrateConfigurationConditions("Debug", "ExportDebug");
|
||||
MigrateConfigurationConditions("Release", "ExportRelease");
|
||||
MigrateConfigurationConditions("Tools", "Debug"); // Must be last
|
||||
}
|
||||
|
||||
|
||||
if (dirty)
|
||||
root.Save();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user