More robust csproj-referencing

also add other relevant project-files to the solution
This commit is contained in:
Simon Lübeß
2026-08-22 18:45:29 +02:00
parent 9ccaf8977a
commit c8d63a9c36
+83 -38
View File
@@ -81,6 +81,27 @@ class Project
Path.ToActualPath(outTarget); Path.ToActualPath(outTarget);
} }
private static void GetScriptCoreGeneratorProjectFilePath(String outTarget)
{
Directory.GetCurrentDirectory(outTarget);
Path.Combine(outTarget, "../ScriptCoreGenerator/ScriptCoreGenerator.csproj");
Path.ToActualPath(outTarget);
}
private static void GetScriptCoreGeneratorTestProjectFilePath(String outTarget)
{
Directory.GetCurrentDirectory(outTarget);
Path.Combine(outTarget, "../ScriptCoreGenerator.Test/ScriptCoreGenerator.Test.csproj");
Path.ToActualPath(outTarget);
}
private static void GetImGuiDotNetProjectFilePath(String outTarget)
{
Directory.GetCurrentDirectory(outTarget);
Path.Combine(outTarget, "../vendor/ImGui.NET/src/ImGui.NET/ImGui.NET.csproj");
Path.ToActualPath(outTarget);
}
/// Loads or creates the user specific settings for this project. /// Loads or creates the user specific settings for this project.
private void InitUserSettings() private void InitUserSettings()
{ {
@@ -275,7 +296,8 @@ class Project
return project; return project;
} }
/// If necessary adds or removes the reference to ScriptCore.csproj from the solution (.slnx) file. /// If missing adds the reference to ScriptCore and other script dependencies from the solution (.slnx) file.
/// @param referenceScriptCoreProject If true, ScriptCore and other dependencies will be referenced using their .csproj-files. Otherwise the ScriptCore-dll will be referenced.
private Result<void> FixupScriptSolutionFile(bool referenceScriptCoreProject) private Result<void> FixupScriptSolutionFile(bool referenceScriptCoreProject)
{ {
String solutionPath = scope .(); String solutionPath = scope .();
@@ -294,48 +316,23 @@ class Project
solution.LoadFromString(solutionFileContent); solution.LoadFromString(solutionFileContent);
XmlNode scriptCoreProjectReference = null;
for (XmlNode projectNode in solution.DocumentElement.EnumerateNodes("Project", recursive: true))
{
if (projectNode.TryGetAttribute("Path", let includeAttribute))
{
if (includeAttribute.Value.Contains("ScriptCore.csproj", true))
{
scriptCoreProjectReference = projectNode;
break;
}
}
}
bool changedContent = false; bool changedContent = false;
if (referenceScriptCoreProject) String scriptCoreFilePath = scope .();
{ GetScriptCoreProjectFilePath(scriptCoreFilePath);
Log.EngineLogger.Info("Debug mode enabled. Referencing ScriptCore.csproj in Script-Solution."); changedContent |= Try!(AddProjectToSolution(solution, scriptCoreFilePath, referenceScriptCoreProject));
if (scriptCoreProjectReference == null) String scriptCoreGeneratorFilePath = scope .();
{ GetScriptCoreGeneratorProjectFilePath(scriptCoreGeneratorFilePath);
Log.EngineLogger.Warning("No reference to ScriptCore.csproj found. Adding..."); changedContent |= Try!(AddProjectToSolution(solution, scriptCoreGeneratorFilePath, referenceScriptCoreProject));
scriptCoreProjectReference = solution.DocumentElement.AddChild("Project");
changedContent = true; String scriptCoreGeneratorTestFilePath = scope .();
} GetScriptCoreGeneratorTestProjectFilePath(scriptCoreGeneratorTestFilePath);
changedContent |= Try!(AddProjectToSolution(solution, scriptCoreGeneratorTestFilePath, referenceScriptCoreProject));
String projectFilePath = scope .(); String imGuiDotNetFilePath = scope .();
GetScriptCoreProjectFilePath(projectFilePath); GetImGuiDotNetProjectFilePath(imGuiDotNetFilePath);
changedContent |= Try!(AddProjectToSolution(solution, imGuiDotNetFilePath, referenceScriptCoreProject));
if (!Path.Equals(scriptCoreProjectReference["Path"], projectFilePath))
{
scriptCoreProjectReference["Path"] = projectFilePath;
changedContent = true;
}
}
else if (scriptCoreProjectReference != null)
{
Log.EngineLogger.Warning("Reference to ScriptCore.csproj found. Removing...");
scriptCoreProjectReference.RemoveFromParent(true);
changedContent = true;
}
if (changedContent) if (changedContent)
{ {
@@ -359,6 +356,54 @@ class Project
return .Ok; return .Ok;
} }
private Result<bool> AddProjectToSolution(Xml solution, StringView projectFilePath, bool referenceScriptCoreProject)
{
String projectName = scope .();
Path.GetFileName(projectFilePath, projectName);
XmlNode projectReference = null;
for (XmlNode projectNode in solution.DocumentElement.EnumerateNodes("Project", recursive: true))
{
if (projectNode.TryGetAttribute("Path", let includeAttribute))
{
if (includeAttribute.Value.Contains(projectName, true))
{
projectReference = projectNode;
break;
}
}
}
bool changedContent = false;
if (referenceScriptCoreProject)
{
Log.EngineLogger.Info($"Debug mode enabled. Referencing {projectName} in Script-Solution.");
if (projectReference == null)
{
Log.EngineLogger.Warning($"No reference to {projectName} found. Adding...");
projectReference = solution.DocumentElement.AddChild("Project");
changedContent = true;
}
if (projectReference["Path"] != projectFilePath)
{
projectReference["Path"] = projectFilePath;
changedContent = true;
}
}
else if (projectReference != null)
{
Log.EngineLogger.Warning($"Reference to {projectName} found. Removing...");
projectReference.RemoveFromParent(true);
changedContent = true;
}
return changedContent;
}
/// If necessary adds or removes the reference to ScriptCore.dll from the project (.csproj) file. /// If necessary adds or removes the reference to ScriptCore.dll from the project (.csproj) file.
private Result<void> FixupScriptProjectFile(bool referenceScriptCoreProject) private Result<void> FixupScriptProjectFile(bool referenceScriptCoreProject)
{ {