|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Reflection;
|
|
using DotNet.Globbing;
|
|
using DotNet.Globbing;
|
|
using Microsoft.Build.Construction;
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
|
@@ -117,6 +118,7 @@ namespace GodotTools.ProjectEditor
|
|
globOptions.Evaluation.CaseInsensitive = false;
|
|
globOptions.Evaluation.CaseInsensitive = false;
|
|
|
|
|
|
var root = ProjectRootElement.Open(projectPath);
|
|
var root = ProjectRootElement.Open(projectPath);
|
|
|
|
+ Debug.Assert(root != null);
|
|
|
|
|
|
foreach (var itemGroup in root.ItemGroups)
|
|
foreach (var itemGroup in root.ItemGroups)
|
|
{
|
|
{
|
|
@@ -158,35 +160,35 @@ namespace GodotTools.ProjectEditor
|
|
void AddPropertyIfNotPresent(string name, string condition, string value)
|
|
void AddPropertyIfNotPresent(string name, string condition, string value)
|
|
{
|
|
{
|
|
if (root.PropertyGroups
|
|
if (root.PropertyGroups
|
|
- .Any(g => (g.Condition == string.Empty || g.Condition == condition) &&
|
|
|
|
|
|
+ .Any(g => (g.Condition == string.Empty || g.Condition.Trim() == condition) &&
|
|
g.Properties
|
|
g.Properties
|
|
.Any(p => p.Name == name &&
|
|
.Any(p => p.Name == name &&
|
|
p.Value == value &&
|
|
p.Value == value &&
|
|
- (p.Condition == condition || g.Condition == condition))))
|
|
|
|
|
|
+ (p.Condition.Trim() == condition || g.Condition.Trim() == condition))))
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- root.AddProperty(name, value).Condition = condition;
|
|
|
|
|
|
+ root.AddProperty(name, value).Condition = " " + condition + " ";
|
|
dirty = true;
|
|
dirty = true;
|
|
}
|
|
}
|
|
|
|
|
|
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
|
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
|
- condition: " '$(Configuration)' != 'Release' ",
|
|
|
|
|
|
+ condition: "'$(Configuration)' != 'ExportRelease'",
|
|
value: "Debug");
|
|
value: "Debug");
|
|
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
|
AddPropertyIfNotPresent(name: "ApiConfiguration",
|
|
- condition: " '$(Configuration)' == 'Release' ",
|
|
|
|
|
|
+ condition: "'$(Configuration)' == 'ExportRelease'",
|
|
value: "Release");
|
|
value: "Release");
|
|
|
|
|
|
void SetReferenceHintPath(string referenceName, string condition, string hintPath)
|
|
void SetReferenceHintPath(string referenceName, string condition, string hintPath)
|
|
{
|
|
{
|
|
foreach (var itemGroup in root.ItemGroups.Where(g =>
|
|
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 =>
|
|
var references = itemGroup.Items.Where(item =>
|
|
item.ItemType == "Reference" &&
|
|
item.ItemType == "Reference" &&
|
|
item.Include == referenceName &&
|
|
item.Include == referenceName &&
|
|
- (item.Condition == condition || itemGroup.Condition == condition));
|
|
|
|
|
|
+ (item.Condition.Trim() == condition || itemGroup.Condition.Trim() == condition));
|
|
|
|
|
|
var referencesWithHintPath = references.Where(reference =>
|
|
var referencesWithHintPath = references.Where(reference =>
|
|
reference.Metadata.Any(m => m.Name == "HintPath"));
|
|
reference.Metadata.Any(m => m.Name == "HintPath"));
|
|
@@ -225,7 +227,7 @@ namespace GodotTools.ProjectEditor
|
|
}
|
|
}
|
|
|
|
|
|
// Found no Reference item at all. Add it.
|
|
// Found no Reference item at all. Add it.
|
|
- root.AddItem("Reference", referenceName).Condition = condition;
|
|
|
|
|
|
+ root.AddItem("Reference", referenceName).Condition = " " + condition + " ";
|
|
dirty = true;
|
|
dirty = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -233,7 +235,7 @@ namespace GodotTools.ProjectEditor
|
|
const string editorProjectName = "GodotSharpEditor";
|
|
const string editorProjectName = "GodotSharpEditor";
|
|
|
|
|
|
const string coreCondition = "";
|
|
const string coreCondition = "";
|
|
- const string editorCondition = " '$(Configuration)' == 'Tools' ";
|
|
|
|
|
|
+ const string editorCondition = "'$(Configuration)' == 'Debug'";
|
|
|
|
|
|
var coreHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{coreProjectName}.dll";
|
|
var coreHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{coreProjectName}.dll";
|
|
var editorHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{editorProjectName}.dll";
|
|
var editorHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{editorProjectName}.dll";
|
|
@@ -241,6 +243,105 @@ namespace GodotTools.ProjectEditor
|
|
SetReferenceHintPath(coreProjectName, coreCondition, coreHintPath);
|
|
SetReferenceHintPath(coreProjectName, coreCondition, coreHintPath);
|
|
SetReferenceHintPath(editorProjectName, editorCondition, editorHintPath);
|
|
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)
|
|
if (dirty)
|
|
root.Save();
|
|
root.Save();
|
|
}
|
|
}
|