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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>TALXIS.DevKit.Build.Dataverse.Tasks</AssemblyName>
<!-- https://github.com/dotnet/vscode-csharp/issues/5786 -->
<!-- <TargetFrameworks>net462;$(NetMinimum);$(NetCurrent)</TargetFrameworks> -->
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net10.0</TargetFrameworks>
<!-- Pack settings -->
<NoPackageAnalysis>true</NoPackageAnalysis>
<IsPackable>true</IsPackable>
Expand All @@ -30,6 +30,7 @@
<PackageReference Include="TALXIS.Platform.Metadata" Version="0.4.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Validation" Version="0.4.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Serialization.Xml" Version="0.4.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Packaging" Version="0.4.0" Condition="'$(TargetFramework)' != 'net472'" />

<!-- Do not add any of the dependencies above to nuspec -->
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
Expand Down
111 changes: 85 additions & 26 deletions src/Dataverse/Tasks/Tasks/InvokeSolutionPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,86 @@ public class InvokeSolutionPackager : Task

public bool UseUnmanagedFileForMissingManaged { get; set; }

public override bool Execute()
{
#if NET10_0_OR_GREATER
return ExecuteWithLibrary();
#else
return ExecuteWithPacCli();
#endif
}

#if NET10_0_OR_GREATER
private bool ExecuteWithLibrary()
{
try
{
var packagerService = new TALXIS.Platform.Metadata.Packaging.SolutionPackagerService();
var managed = string.Equals(PackageType, "Managed", StringComparison.OrdinalIgnoreCase);

var options = new TALXIS.Platform.Metadata.Packaging.SolutionPackagerOptions
{
Managed = managed,
Localize = Localize,
UseUnmanagedFileForMissingManaged = UseUnmanagedFileForMissingManaged,
MappingFilePath = MappingFilePath,
LogFilePath = LogFilePath,
SourceLocale = LocalTemplate
};

if (!string.IsNullOrWhiteSpace(ErrorLevel) &&
Enum.TryParse<System.Diagnostics.TraceLevel>(ErrorLevel, true, out var traceLevel))
{
options.ErrorLevel = traceLevel;
}

switch (Action.ToLower())
{
case "pack":
Log.LogMessage(MessageImportance.High, $"Packing solution from '{SolutionRootDirectory}' to '{PathToZipFile}'...");
packagerService.Pack(SolutionRootDirectory, PathToZipFile, options);
Log.LogMessage(MessageImportance.High, "Solution packed successfully.");
break;
case "unpack":
Log.LogMessage(MessageImportance.High, $"Unpacking solution from '{PathToZipFile}' to '{SolutionRootDirectory}'...");
packagerService.Unpack(PathToZipFile, SolutionRootDirectory, options);
Log.LogMessage(MessageImportance.High, "Solution unpacked successfully.");
break;
default:
Log.LogError($"Unsupported action: {Action}");
return false;
}

return true;
}
catch (Exception ex)
{
Log.LogError($"Solution {Action.ToLower()} failed: {ex.Message}");
return false;
}
}
#endif

#if !NET10_0_OR_GREATER
private bool ExecuteWithPacCli()
{
var pacPath = ResolvePACFilePath();
if (pacPath == null)
{
Log.LogError("The pac tool is not found. Please install it using 'dotnet tool install --global Microsoft.PowerApps.CLI.Tool'");
return false;
}

var args = BuildArguments();
if (string.IsNullOrWhiteSpace(args))
{
Log.LogError("Failed to build arguments for pac command.");
return false;
}

return RunCommand(pacPath, args);
}

private string ResolvePACFilePath()
{
bool isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
Expand All @@ -38,7 +118,6 @@ private string ResolvePACFilePath()
? new[] { "pac.exe", "pac.cmd" }
: new[] { "pac" };

// Check the standalone Power Platform CLI location first (preferred, supports latest versions)
if (isWindows)
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Expand All @@ -50,7 +129,6 @@ private string ResolvePACFilePath()
}
}

// Check the standard global tools location
var toolsDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".dotnet", "tools");
Expand All @@ -62,13 +140,12 @@ private string ResolvePACFilePath()
return globalToolPath;
}

// Fall back to searching PATH
var pathEnv = Environment.GetEnvironmentVariable("PATH");

if (!string.IsNullOrEmpty(pathEnv))
{
var separator = isWindows ? ';' : ':';

foreach (var name in candidates)
{
var found = pathEnv.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
Expand All @@ -85,25 +162,6 @@ private string ResolvePACFilePath()
return null;
}

public override bool Execute()
{
var pacPath = ResolvePACFilePath();
if (pacPath == null)
{
Log.LogError("The pac tool is not found. Please install it using 'dotnet tool install --global Microsoft.PowerApps.CLI.Tool'");
return false;
}

var args = BuildArguments();
if (string.IsNullOrWhiteSpace(args))
{
Log.LogError("Failed to build arguments for pac command.");
return false;
}

return RunCommand(pacPath, args);
}

private string BuildArguments()
{
string args = string.Empty;
Expand Down Expand Up @@ -153,8 +211,8 @@ private bool RunCommand(string fileName, string arguments)
{
try
{
var stdoutLines = new System.Collections.Generic.List<string>();
var stderrLines = new System.Collections.Generic.List<string>();
var stdoutLines = new List<string>();
var stderrLines = new List<string>();

ProcessStartInfo processStartInfo = new ProcessStartInfo
{
Expand Down Expand Up @@ -240,4 +298,5 @@ private bool RunCommand(string fileName, string arguments)
return false;
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>

<ThisPackageBuildExtensionsDirectory Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)net6.0\</ThisPackageBuildExtensionsDirectory>
<ThisPackageBuildExtensionsDirectory Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)net10.0\</ThisPackageBuildExtensionsDirectory>
<ThisPackageBuildExtensionsDirectory Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)net472\</ThisPackageBuildExtensionsDirectory>
</PropertyGroup>

Expand Down