Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GodotAddinVS/GodotAddinVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Clide" Version="4.1.1" ExcludeAssets="runtime" />
Expand Down
36 changes: 35 additions & 1 deletion GodotAddinVS/GodotSolutionEventsListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GodotAddinVS.GodotMessaging;
using GodotTools.IdeMessaging;
using GodotTools.IdeMessaging.Requests;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

Expand Down Expand Up @@ -85,7 +86,7 @@ public override int OnAfterOpenProject(IVsHierarchy hierarchy, int added)
if (_registered)
return 0;

_godotProjectDir = SolutionDir;
_godotProjectDir = EvalGodotProjectDir(hierarchy);

DebuggerEvents = ServiceProvider.GetService<DTE>().Events.DebuggerEvents;
DebuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode;
Expand Down Expand Up @@ -162,5 +163,38 @@ private void Close()
DebuggerEvents = null;
}
}

private string EvalGodotProjectDir(IVsHierarchy hierarchy)
{
try
{
ThreadHelper.ThrowIfNotOnUIThread();
var dteProject = GetDTEProject(hierarchy);
if (dteProject == null)
{
return SolutionDir;
}

var evalProj = new Microsoft.Build.Evaluation.Project(dteProject.FullName);
var evaluated = evalProj.GetPropertyValue("GodotProjectDir");
return string.IsNullOrWhiteSpace(evaluated) ? SolutionDir : evaluated;
}
catch
{
return SolutionDir;
}
}

private static EnvDTE.Project GetDTEProject(IVsHierarchy hierarchy)
{
ThreadHelper.ThrowIfNotOnUIThread();

var itemid = VSConstants.VSITEMID_ROOT;

object objProj;
hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out objProj);

return objProj as EnvDTE.Project;
}
}
}