Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 28, 2025

Resolves #34 by implementing multi-location PAC CLI detection to support Power Apps CLI installed via the Power Platform Tools VS Code extension.

Problem

When Power Apps CLI is installed through the VS Code extension (rather than globally), the tool incorrectly shows "Power Apps CLI Not Detected" even though PAC is available. This happens because the current detection logic only checks for the pac command in the system PATH, missing the VS Code extension installation location.

Solution

Added intelligent multi-location PAC detection that checks both standard and VS Code extension locations:

  1. First tries the standard pac command (global installation)
  2. Then checks the VS Code extension location: %APPDATA%\Code\User\globalStorage\microsoft-isvexptools.powerplatform-vscode\pac\tools\pac.exe
  3. Validates that the found PAC executable actually works before using it

Implementation Details

  • Added FindPacPath() method: Similar to the existing FindMsBuildPath() pattern, with session caching for performance
  • Extended Commands.Pac.Check(): Added overload to support custom PAC executable paths
  • Updated CheckPacVersion(): Now uses multi-location detection while maintaining all existing functionality

Backward Compatibility

Fully backward compatible - existing global PAC installations continue to work exactly as before
Graceful fallback - if VS Code detection fails, the tool falls back to original behavior
No breaking changes - all existing method signatures and functionality preserved

Testing Scenarios

The fix correctly handles all installation scenarios:

  • Global PAC only: Uses global installation (existing behavior unchanged)
  • VS Code extension only: Now detects and uses VS Code installation (fixes the issue)
  • Both available: Prefers global installation (maintains standard behavior)
  • Neither available: Shows "not detected" message (existing behavior unchanged)

Users with VS Code extension installations will now see their PAC version information instead of the "Not Detected" error, enabling full functionality of the PCF Custom Control Builder tool.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Power Apps CLI not detected</issue_title>
<issue_description>### Contact Details

kiril.iliev@windowslive.com

What happened?

Based on #34 , I've found that if I just had Power Apps CLI installed per user (for example, through Power Platform Tools VS Code extension), we will need to reference it from there.

Here is a suggestion for an additional check and reference for PAC:

  1. Get user's current roaming folder
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

  2. Concatenate the path to the extension's executable
    ${YourAppDataFolderPath}\Code\User\globalStorage\microsoft-isvexptools.powerplatform-vscode\pac\tools\pac.exe

What version of the tool are you using?

2.2023.6.162

What version of XrmToolBox are you running?

1.2023.12.68

Relevant log output

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #70

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 28, 2025 20:50
Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Copilot AI changed the title [WIP] [Bug]: Power Apps CLI not detected Fix PAC CLI detection for VS Code extension installations Sep 28, 2025
Copilot finished work on behalf of Power-Maverick September 28, 2025 20:55
@Power-Maverick Power-Maverick marked this pull request as ready for review September 30, 2025 21:47
Copilot AI review requested due to automatic review settings September 30, 2025 21:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes PAC CLI detection issues when Power Apps CLI is installed via VS Code extension rather than globally. The enhancement implements intelligent multi-location detection that first checks for global PAC installation, then falls back to the VS Code extension location, ensuring compatibility across different installation scenarios.

  • Implements multi-location PAC CLI detection with session caching for performance
  • Adds overload method for custom PAC executable paths
  • Maintains full backward compatibility with existing global installations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
PCFBuilder.cs Adds FindPacPath() method with caching and updates CheckPacVersion() to use multi-location detection
Commands.cs Adds overload method Check(string pacPath) to support custom PAC executable paths

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +969 to +973
string[] standardCommands = new string[] { Commands.Pac.Check() };
var standardOutput = CommandLineHelper.RunCommand(standardCommands);

StringHelper stringer = new StringHelper();
PacVersionParsedDetails standardPacDetails = stringer.ParsePacVersionOutput(standardOutput);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The PAC checking logic is duplicated between FindPacPath() and CheckPacVersion() methods. Consider extracting this into a private helper method to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +1002 to +1005
catch (Exception)
{
// If there's any error accessing the VS Code extension path, continue with standard behavior
}
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching all exceptions with a generic Exception catch block is discouraged. Consider catching specific exceptions like UnauthorizedAccessException, DirectoryNotFoundException, or PathTooLongException to handle only the expected error scenarios.

Suggested change
catch (Exception)
{
// If there's any error accessing the VS Code extension path, continue with standard behavior
}
catch (UnauthorizedAccessException)
{
// If there's any error accessing the VS Code extension path, continue with standard behavior
}
catch (DirectoryNotFoundException)
{
// If there's any error accessing the VS Code extension path, continue with standard behavior
}
catch (PathTooLongException)
{
// If there's any error accessing the VS Code extension path, continue with standard behavior
}

Copilot uses AI. Check for mistakes.
@Power-Maverick Power-Maverick merged commit 201dc76 into master Sep 30, 2025
3 checks passed
@Power-Maverick Power-Maverick deleted the copilot/fix-18353345-ec73-4953-92e7-04be4b377313 branch September 30, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Power Apps CLI not detected Power Apps CLI not detected on this machine

2 participants