I want to run a SPFx web part through DevOps build pipeline once, and have the same artifacts be deployable to any environment.
Currently I have a setup where there are #{PlaceHolders}# in the code which are to be replaced by the Replace Tokens task in a DevOps release pipeline. To do this I have added an Extract activity to unzip the .sppkg package, after which I replace the tokens in the generated .zip file, and then I archive the files back into a .sppkg package.
The issue I run into is that seemingly, SharePoint doesn't like me tampering with it's .sppkg files. In the app catalog, I get this in the column App Package Error Message whenever I have replaced the tokens:
The package contains the wrong number of relationships for relationship type 'http://schemas.microsoft.com/sharepoint/2012/app/relationships/package-manifest'. Expected: '1'. Actual: '0'.
Any clue on how I can safely modify the .sppkg package is appreciated, or how I otherwise can implement environment variables into my SFPx web parts after the solution is packaged.
The goal is to being able to promote one and the same build to subsequent environments in Azure DevOps.
Edit providing release pipeline details
Using the standard Extract files and Archive files tasks, these are the settings used:
Archive patterns: $(System.DefaultWorkingDirectory)/MyProjectFolder/drop/SharePoint/solution/my-package.sppkg
Destination folder: $(System.DefaultWorkingDirectory)/MyProjectFolder/drop/SharePoint/solution/extracts
Root folder or file to archive: $(System.DefaultWorkingDirectory)/MyProjectFolder/drop/sharepoint/solution/extracts
Archive file to create: $(System.DefaultWorkingDirectory)/MyProjectFolder/drop/sharepoint/solution/my-package.sppkg
Also I tried modifying the .sppkg package locally after also building locally but to the same result. So I'm thinking there might be a signature that gets added to .sppkg packages that's looking for length, and if changed, it might get denied?
I was running into the same issue using PowerShell "Compress-Archive", but when I switched to 7zip I was able to extract the sppkg, replace placeholders, re-zip and the app catalog accepted the new sppkg.
The "Compress-Archive" issue for me was also fixed by updating Microsoft.PowerShell.Archive to > 1.2.3.0, see: link