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
12 changes: 1 addition & 11 deletions src/Dataverse/Tasks/TALXIS.DevKit.Build.Dataverse.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,14 @@
<!--<PackageReference Include="LibGit2Sharp" Version="0.26.2" />-->
<PackageReference Include="Microsoft.Build" Version="18.0.2" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="18.0.2" />
<PackageReference Include="Microsoft.PowerApps.CLI.Core.linux-x64" Version="2.6.4" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="TALXIS.Platform.Metadata" Version="0.6.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Validation" Version="0.6.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Serialization.Xml" Version="0.6.0" />
<PackageReference Include="TALXIS.Platform.Metadata.Packaging" Version="0.7.0" />

<!-- Do not add any of the dependencies above to nuspec -->
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Reference Include="SolutionPackagerLib">
<HintPath>$(PkgMicrosoft_PowerApps_CLI_Core_linux-x64)\tools\SolutionPackagerLib.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="System.IO.Packaging">
<HintPath>$(PkgMicrosoft_PowerApps_CLI_Core_linux-x64)\tools\System.IO.Packaging.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<PropertyGroup>
<Authors>TALXIS</Authors>
<Copyright>2025 NETWORG</Copyright>
Expand Down
91 changes: 43 additions & 48 deletions src/Dataverse/Tasks/Tasks/InvokeSolutionPackager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Crm.Tools.SolutionPackager;
using TALXIS.Platform.Metadata.Packaging;

public class InvokeSolutionPackager : Task
{
Expand Down Expand Up @@ -32,15 +32,30 @@ public override bool Execute()
{
try
{
var arguments = BuildArguments();
if (arguments == null)
var options = BuildOptions();
if (options == null)
{
return false;
}

var packager = new SolutionPackager(arguments);
packager.Run();
return true;
var packager = new SolutionPackagerService();

switch (Action.ToLowerInvariant())
{
case "pack":
Log.LogMessage(MessageImportance.High, $"Packing solution from '{SolutionRootDirectory}' to '{PathToZipFile}'...");
packager.Pack(SolutionRootDirectory, PathToZipFile, options);
Log.LogMessage(MessageImportance.High, "Solution packed successfully.");
return true;
case "unpack":
Log.LogMessage(MessageImportance.High, $"Unpacking solution from '{PathToZipFile}' to '{SolutionRootDirectory}'...");
packager.Unpack(PathToZipFile, SolutionRootDirectory, options);
Log.LogMessage(MessageImportance.High, "Solution unpacked successfully.");
return true;
default:
Log.LogError($"Unsupported action: {Action}");
return false;
}
}
catch (Exception ex)
{
Expand All @@ -56,9 +71,9 @@ public override bool Execute()
}
}

private PackagerArguments BuildArguments()
private SolutionPackagerOptions BuildOptions()
{
if (!TryParsePackageType(out var packageType))
if (!TryParseManaged(out var managed))
{
return null;
}
Expand All @@ -69,75 +84,55 @@ private PackagerArguments BuildArguments()
return null;
}

PackagerArguments arguments;
var options = new SolutionPackagerOptions
{
Managed = managed,
ErrorLevel = errorLevel,
Localize = Localize,
UseUnmanagedFileForMissingManaged = UseUnmanagedFileForMissingManaged,
};

switch (Action.ToLowerInvariant())
if (!string.IsNullOrWhiteSpace(LogFilePath))
{
case "pack":
arguments = new PackagerArguments
{
Action = CommandAction.Pack,
PathToZipFile = PathToZipFile,
Folder = SolutionRootDirectory,
PackageType = packageType,
ErrorLevel = errorLevel,
Localize = Localize,
UseUnmanagedFileForManaged = UseUnmanagedFileForMissingManaged,
};
break;
case "unpack":
arguments = new PackagerArguments
{
Action = CommandAction.Extract,
PathToZipFile = PathToZipFile,
Folder = SolutionRootDirectory,
PackageType = packageType,
AllowDeletes = AllowDelete.Yes,
AllowWrites = AllowWrite.Yes,
ErrorLevel = errorLevel,
Localize = Localize,
};
break;
default:
Log.LogError($"Unsupported action: {Action}");
return null;
options.LogFilePath = LogFilePath;
}

if (!string.IsNullOrWhiteSpace(MappingFilePath))
{
arguments.MappingFile = MappingFilePath;
options.MappingFilePath = MappingFilePath;
}

if (!string.IsNullOrWhiteSpace(LogFilePath))
if (!string.IsNullOrWhiteSpace(LocalTemplate))
{
arguments.LogFile = LogFilePath;
options.SourceLocale = LocalTemplate;
}

if (!string.IsNullOrWhiteSpace(LocalTemplate))
if (string.Equals(Action, "unpack", StringComparison.OrdinalIgnoreCase))
{
arguments.LocaleTemplate = LocalTemplate;
options.AllowDeletes = true;
options.AllowWrites = true;
}

return arguments;
return options;
}

private bool TryParsePackageType(out SolutionPackageType packageType)
private bool TryParseManaged(out bool managed)
{
if (string.IsNullOrWhiteSpace(PackageType) ||
string.Equals(PackageType, "Unmanaged", StringComparison.OrdinalIgnoreCase))
{
packageType = SolutionPackageType.Unmanaged;
managed = false;
return true;
}

if (string.Equals(PackageType, "Managed", StringComparison.OrdinalIgnoreCase))
{
packageType = SolutionPackageType.Managed;
managed = true;
return true;
}

Log.LogError($"Unsupported package type: {PackageType}");
packageType = default;
managed = false;
return false;
}
}