@@ -34,6 +34,7 @@ public partial class PCFBuilder : PluginControlBase, IGitHubPlugin, IHelpPlugin,
3434 {
3535 #region XrmToolBox settings
3636 private Settings pluginSettings ;
37+ private string detectedPacPath ; // Cache the detected PAC path for session reuse
3738
3839 public string RepositoryName => "PCF-CustomControlBuilder" ;
3940 public string UserName => "Power-Maverick" ;
@@ -810,8 +811,30 @@ public void CheckPacVersion(object worker, DoWorkEventArgs args)
810811 {
811812 var start = DateTime . Now ;
812813
813- string [ ] commands = new string [ ] { Commands . Pac . Check ( ) } ;
814- var output = CommandLineHelper . RunCommand ( commands ) ;
814+ // Try to find PAC in multiple locations
815+ string pacPath = FindPacPath ( ) ;
816+ string [ ] commands ;
817+ string output ;
818+
819+ if ( ! string . IsNullOrEmpty ( pacPath ) )
820+ {
821+ // Use the found PAC path
822+ if ( pacPath . Equals ( "pac" , StringComparison . InvariantCultureIgnoreCase ) )
823+ {
824+ commands = new string [ ] { Commands . Pac . Check ( ) } ;
825+ }
826+ else
827+ {
828+ commands = new string [ ] { Commands . Pac . Check ( pacPath ) } ;
829+ }
830+ output = CommandLineHelper . RunCommand ( commands ) ;
831+ }
832+ else
833+ {
834+ // Fallback to standard check for backward compatibility
835+ commands = new string [ ] { Commands . Pac . Check ( ) } ;
836+ output = CommandLineHelper . RunCommand ( commands ) ;
837+ }
815838
816839 StringHelper stringer = new StringHelper ( ) ;
817840 PacVersionParsedDetails outputParsedPacDetails = stringer . ParsePacVersionOutput ( output ) ;
@@ -944,6 +967,56 @@ private string FindMsBuildPath()
944967 return msBuildPath ;
945968 }
946969
970+ private string FindPacPath ( )
971+ {
972+ // Return cached path if available
973+ if ( ! string . IsNullOrEmpty ( detectedPacPath ) )
974+ {
975+ return detectedPacPath ;
976+ }
977+
978+ // First try the standard PAC command (global installation)
979+ string [ ] standardCommands = new string [ ] { Commands . Pac . Check ( ) } ;
980+ var standardOutput = CommandLineHelper . RunCommand ( standardCommands ) ;
981+
982+ StringHelper stringer = new StringHelper ( ) ;
983+ PacVersionParsedDetails standardPacDetails = stringer . ParsePacVersionOutput ( standardOutput ) ;
984+
985+ // If PAC is found via standard command, use it
986+ if ( ! standardPacDetails . CLINotFound )
987+ {
988+ detectedPacPath = "pac" ; // Cache the result
989+ return detectedPacPath ;
990+ }
991+
992+ // Try VS Code extension location
993+ try
994+ {
995+ string appDataPath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
996+ string vscodeExtensionPacPath = Path . Combine ( appDataPath , "Code" , "User" , "globalStorage" , "microsoft-isvexptools.powerplatform-vscode" , "pac" , "tools" , "pac.exe" ) ;
997+
998+ if ( File . Exists ( vscodeExtensionPacPath ) )
999+ {
1000+ // Test if this PAC installation works by running it
1001+ string [ ] vscodeCommands = new string [ ] { Commands . Pac . Check ( vscodeExtensionPacPath ) } ;
1002+ var vscodeOutput = CommandLineHelper . RunCommand ( vscodeCommands ) ;
1003+
1004+ PacVersionParsedDetails vscodePacDetails = stringer . ParsePacVersionOutput ( vscodeOutput ) ;
1005+ if ( ! vscodePacDetails . CLINotFound )
1006+ {
1007+ detectedPacPath = vscodeExtensionPacPath ; // Cache the result
1008+ return detectedPacPath ;
1009+ }
1010+ }
1011+ }
1012+ catch ( Exception )
1013+ {
1014+ // If there's any error accessing the VS Code extension path, continue with standard behavior
1015+ }
1016+
1017+ return string . Empty ; // PAC not found in any location
1018+ }
1019+
9471020 private void IncrementComponentVersion ( )
9481021 {
9491022 var start = DateTime . Now ;
0 commit comments