Skip to content

Commit 771d576

Browse files
authored
fix(vcproject): use dynamic binding to avoid VCProjectEngine assembly load failure (#34)
Replace compile-time VCProjectEngine reference with dynamic late binding so the assembly is only resolved at runtime for C++ projects, preventing FileNotFoundException for users without the C++ workload installed.
1 parent f773a9d commit 771d576

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/CodingWithCalvin.OpenBinFolder/CodingWithCalvin.OpenBinFolder.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
<PackageReference Include="CodingWithCalvin.Otel4Vsix" Version="0.2.2" />
1313
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
1414
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.*" PrivateAssets="all" />
15-
<PackageReference Include="Microsoft.VisualStudio.VCProjectEngine" Version="17.14.40264">
16-
<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
17-
</PackageReference>
15+
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1816
</ItemGroup>
1917

2018
<ItemGroup>

src/CodingWithCalvin.OpenBinFolder/Commands/OpenBinFolderCommand.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using EnvDTE;
88
using EnvDTE80;
99
using Microsoft.VisualStudio.Shell;
10-
using Microsoft.VisualStudio.VCProjectEngine;
1110
using Project = EnvDTE.Project;
1211

1312
namespace CodingWithCalvin.OpenBinFolder.Commands
@@ -102,9 +101,9 @@ private void OpenProjectBinFolder(Project project)
102101

103102
string projectBinPath;
104103

105-
if (IsCppProject(project.Kind) && project.Object is VCProject vcProject)
104+
if (IsCppProject(project.Kind))
106105
{
107-
projectBinPath = GetCppOutputPath(vcProject, projectPath);
106+
projectBinPath = GetCppOutputPath(project.Object, projectPath);
108107
}
109108
else
110109
{
@@ -142,16 +141,16 @@ bool IsCppProject(string projectKind)
142141
return string.Equals(projectKind, CppProjectKind, StringComparison.OrdinalIgnoreCase);
143142
}
144143

145-
string GetCppOutputPath(VCProject vcProject, string projectPath)
144+
string GetCppOutputPath(dynamic vcProject, string projectPath)
146145
{
147-
var activeConfig = vcProject.ActiveConfiguration as VCConfiguration;
146+
dynamic activeConfig = vcProject.ActiveConfiguration;
148147
if (activeConfig == null)
149148
{
150149
throw new InvalidOperationException("Unable to get active configuration for C++ project");
151150
}
152151

153152
// Evaluate expands macros like $(OutDir), $(Configuration), $(Platform), etc.
154-
var outDir = activeConfig.Evaluate("$(OutDir)");
153+
string outDir = activeConfig.Evaluate("$(OutDir)");
155154

156155
if (Path.IsPathRooted(outDir))
157156
{

0 commit comments

Comments
 (0)