Skip to content

Commit a1f81dd

Browse files
committed
Fix launch issue when GodotProjectDir not same as SolutionDir
If the Solution for a Godot project is not the same as the project directory the extension will fail to launch the debug target with a MessageBox showing 'No Godot editor instance connected'. The reason is that the extension takes SolutionDir as the Godot project dir. While this hold true for simple default Godot projects this must not be the case. In complex projects developers may restructure their projects into a alternative structure, where the solution may be at another location. The *.csproj file has the MSBuild property 'GodotProjectDir'. Now the value of this property is fetched and will be used as the project dir. Note: Godot itself has some issues with projects varying to the default project. To fix this godot issues, modifications in the GodotSDK MSBuild props file have to be done.
1 parent f286e29 commit a1f81dd

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

GodotAddinVS/GodotAddinVS.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@
7171
</None>
7272
</ItemGroup>
7373
<ItemGroup>
74+
<Reference Include="Microsoft.Build" />
7475
<Reference Include="Microsoft.CSharp" />
7576
<Reference Include="System" />
77+
<Reference Include="System.Xml" />
7678
</ItemGroup>
7779
<ItemGroup>
7880
<PackageReference Include="Clide" Version="4.1.1" ExcludeAssets="runtime" />

GodotAddinVS/GodotSolutionEventsListener.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using GodotAddinVS.GodotMessaging;
99
using GodotTools.IdeMessaging;
1010
using GodotTools.IdeMessaging.Requests;
11+
using Microsoft.VisualStudio;
1112
using Microsoft.VisualStudio.Shell;
1213
using Microsoft.VisualStudio.Shell.Interop;
1314

@@ -85,7 +86,7 @@ public override int OnAfterOpenProject(IVsHierarchy hierarchy, int added)
8586
if (_registered)
8687
return 0;
8788

88-
_godotProjectDir = SolutionDir;
89+
_godotProjectDir = EvalGodotProjectDir(hierarchy);
8990

9091
DebuggerEvents = ServiceProvider.GetService<DTE>().Events.DebuggerEvents;
9192
DebuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode;
@@ -162,5 +163,38 @@ private void Close()
162163
DebuggerEvents = null;
163164
}
164165
}
166+
167+
private string EvalGodotProjectDir(IVsHierarchy hierarchy)
168+
{
169+
try
170+
{
171+
ThreadHelper.ThrowIfNotOnUIThread();
172+
var dteProject = GetDTEProject(hierarchy);
173+
if (dteProject == null)
174+
{
175+
return SolutionDir;
176+
}
177+
178+
var evalProj = new Microsoft.Build.Evaluation.Project(dteProject.FullName);
179+
var evaluated = evalProj.GetPropertyValue("GodotProjectDir");
180+
return evaluated;
181+
}
182+
catch
183+
{
184+
return SolutionDir;
185+
}
186+
}
187+
188+
private static EnvDTE.Project GetDTEProject(IVsHierarchy hierarchy)
189+
{
190+
ThreadHelper.ThrowIfNotOnUIThread();
191+
192+
var itemid = VSConstants.VSITEMID_ROOT;
193+
194+
object objProj;
195+
hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out objProj);
196+
197+
return objProj as EnvDTE.Project;
198+
}
165199
}
166200
}

0 commit comments

Comments
 (0)