Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="CodingWithCalvin.VsixSdk/0.3.0">
<Project Sdk="CodingWithCalvin.VsixSdk/0.4.0">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
Expand All @@ -11,6 +11,8 @@
<ItemGroup>
<PackageReference Include="CodingWithCalvin.Otel4Vsix" Version="0.2.2" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.*" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.VCProjectEngine" Version="17.14.40264" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.VCProjectEngine;
using Project = EnvDTE.Project;

namespace CodingWithCalvin.OpenBinFolder.Commands
{
internal class OpenBinFolderCommand
{
// Project type GUIDs
private const string CSharpProjectKind = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}";
private const string VbNetProjectKind = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}";
private const string FSharpProjectKind = "{F2A71F9B-5D33-465A-A702-920D77279786}";
private const string CppProjectKind = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";

private readonly Package _package;

private OpenBinFolderCommand(Package package)
Expand Down Expand Up @@ -93,11 +100,19 @@ private void OpenProjectBinFolder(Project project)
Path.GetDirectoryName(project.FullName)
?? throw new InvalidOperationException();

var projectOutputPath = project
.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")
.Value.ToString();
string projectBinPath;

var projectBinPath = Path.Combine(projectPath, projectOutputPath);
if (IsCppProject(project.Kind) && project.Object is VCProject vcProject)
{
projectBinPath = GetCppOutputPath(vcProject, projectPath);
}
else
{
var projectOutputPath = project
.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")
.Value.ToString();
projectBinPath = Path.Combine(projectPath, projectOutputPath);
}

System.Diagnostics.Process.Start(
Directory.Exists(projectBinPath) ? projectBinPath : projectPath
Expand All @@ -121,6 +136,30 @@ private void OpenProjectBinFolder(Project project)
Exception: {ex.Message}"
);
}

bool IsCppProject(string projectKind)
{
return string.Equals(projectKind, CppProjectKind, StringComparison.OrdinalIgnoreCase);
}

string GetCppOutputPath(VCProject vcProject, string projectPath)
{
var activeConfig = vcProject.ActiveConfiguration as VCConfiguration;
if (activeConfig == null)
{
throw new InvalidOperationException("Unable to get active configuration for C++ project");
}

// Evaluate expands macros like $(OutDir), $(Configuration), $(Platform), etc.
var outDir = activeConfig.Evaluate("$(OutDir)");

if (Path.IsPathRooted(outDir))
{
return outDir;
}

return Path.Combine(projectPath, outDir);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"Debug Extension": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\Microsoft Visual Studio\\18\\Community\\Common7\\IDE\\devenv.exe",
"commandLineArgs": "/rootSuffix Exp"
}
}
}