When you make a change to a PowerShell Module Manifest and go to commit those changes in Git, I have observed for some time that it was not possible to see the actual changes in the file because Git was showing it as a binary file. I finally found out why this happens……
Take the following example. I’ve created a module manifest for a module Test with New-ModuleManifest:
Now I make a change to the manifest, say up the version to 1.1
When I go to commit the file, I don’t see what has actually changed in the file. Git reports that it is a binary file:
This is because the output from New-ModuleManifest uses UTF16 for encoding, hence Git sees it as a binary file.
Using the handy encoding functions from here we can check the encoding for the manifest file:
I learnt this from the regular PowerShell community call where there was a discussion around standardising on the encoding for all cmdlets in PowerShell Core 6. In versions prior to 6 different cmdlets use different encodings types, so it seems like a good opportunity to standardise, particularly with the move to make PowerShell cross-platform and Linux having a default encoding of UTF8. There is a lot more information here on the proposal for PowerShell Core and encoding going forward.
So, let’s change the encoding of the manifest file to UTF8:
Now let’s change the manifest file again and see if we can view the changes in Git:
Or in VS Code:
Happy Days 🙂
Thanks to Joey Aiello for sharing this on today’s community call.