Fix C# solution directory settings

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
This commit is contained in:
NeilKleistGao 2022-11-29 23:32:11 +08:00
parent cd491c6e47
commit 2bab84c8c7
3 changed files with 13 additions and 14 deletions

View File

@ -12,8 +12,7 @@
<Configurations>Debug;ExportDebug;ExportRelease</Configurations> <Configurations>Debug;ExportDebug;ExportRelease</Configurations>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<GodotProjectDir Condition=" '$(SolutionDir)' != '' ">$(SolutionDir)</GodotProjectDir> <GodotProjectDir Condition=" '$(GodotProjectDir)' == '' ">$(MSBuildProjectDirectory)</GodotProjectDir>
<GodotProjectDir Condition=" '$(SolutionDir)' == '' ">$(MSBuildProjectDirectory)</GodotProjectDir>
<GodotProjectDir>$([MSBuild]::EnsureTrailingSlash('$(GodotProjectDir)'))</GodotProjectDir> <GodotProjectDir>$([MSBuild]::EnsureTrailingSlash('$(GodotProjectDir)'))</GodotProjectDir>
<!-- Custom output paths for Godot projects. In brief, 'bin\' and 'obj\' are moved to '$(GodotProjectDir)\.godot\mono\temp\'. --> <!-- Custom output paths for Godot projects. In brief, 'bin\' and 'obj\' are moved to '$(GodotProjectDir)\.godot\mono\temp\'. -->

View File

@ -57,24 +57,22 @@ namespace GodotTools
{ {
pr.Step("Generating C# project...".TTR()); pr.Step("Generating C# project...".TTR());
string resourceDir = ProjectSettings.GlobalizePath("res://"); string csprojDir = Path.GetDirectoryName(GodotSharpDirs.ProjectCsProjPath);
string slnDir = Path.GetDirectoryName(GodotSharpDirs.ProjectSlnPath);
string path = resourceDir;
string name = GodotSharpDirs.ProjectAssemblyName; string name = GodotSharpDirs.ProjectAssemblyName;
string guid = CsProjOperations.GenerateGameProject(csprojDir, name);
string guid = CsProjOperations.GenerateGameProject(path, name);
if (guid.Length > 0) if (guid.Length > 0)
{ {
var solution = new DotNetSolution(name) var solution = new DotNetSolution(name)
{ {
DirectoryPath = path DirectoryPath = slnDir
}; };
var projectInfo = new DotNetSolution.ProjectInfo var projectInfo = new DotNetSolution.ProjectInfo
{ {
Guid = guid, Guid = guid,
PathRelativeToSolution = name + ".csproj", PathRelativeToSolution = Path.GetRelativePath(slnDir, GodotSharpDirs.ProjectCsProjPath),
Configs = new List<string> { "Debug", "ExportDebug", "ExportRelease" } Configs = new List<string> { "Debug", "ExportDebug", "ExportRelease" }
}; };
@ -375,6 +373,8 @@ namespace GodotTools
{ {
base._EnablePlugin(); base._EnablePlugin();
ProjectSettingsChanged += GodotSharpDirs.DetermineProjectLocation;
if (Instance != null) if (Instance != null)
throw new InvalidOperationException(); throw new InvalidOperationException();
Instance = this; Instance = this;

View File

@ -52,10 +52,9 @@ namespace GodotTools.Internals
{ {
GlobalDef("dotnet/project/assembly_name", ""); GlobalDef("dotnet/project/assembly_name", "");
GlobalDef("dotnet/project/solution_directory", ""); GlobalDef("dotnet/project/solution_directory", "");
GlobalDef("dotnet/project/c#_project_directory", "");
} }
private static void DetermineProjectLocation() public static void DetermineProjectLocation()
{ {
static string DetermineProjectName() static string DetermineProjectName()
{ {
@ -76,10 +75,11 @@ namespace GodotTools.Internals
string slnParentDir = (string)ProjectSettings.GetSetting("dotnet/project/solution_directory"); string slnParentDir = (string)ProjectSettings.GetSetting("dotnet/project/solution_directory");
if (string.IsNullOrEmpty(slnParentDir)) if (string.IsNullOrEmpty(slnParentDir))
slnParentDir = "res://"; slnParentDir = "res://";
else if (!slnParentDir.StartsWith("res://"))
slnParentDir = "res://" + slnParentDir;
string csprojParentDir = (string)ProjectSettings.GetSetting("dotnet/project/c#_project_directory"); // The csproj should be in the same folder as project.godot.
if (string.IsNullOrEmpty(csprojParentDir)) string csprojParentDir = "res://";
csprojParentDir = "res://";
_projectSlnPath = Path.Combine(ProjectSettings.GlobalizePath(slnParentDir), _projectSlnPath = Path.Combine(ProjectSettings.GlobalizePath(slnParentDir),
string.Concat(_projectAssemblyName, ".sln")); string.Concat(_projectAssemblyName, ".sln"));