Last active
November 23, 2020 11:44
-
-
Save riverar/4046c3f97582e63dca618ab7f99cd337 to your computer and use it in GitHub Desktop.
Hololens appx/appxbundle publishing cmdlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Very preliminary Hololens appx/appxbundle publishing cmdlet to stand-in for | |
# Windows 10 SDK's WinAppDeployCmd which doesn't seem to support HoloLens | |
# | |
# https://gist.github.com/riverar/4046c3f97582e63dca618ab7f99cd337 | |
# | |
# Working: | |
# - Basic uploading of appx/appxbundle over HTTP | |
# | |
# Missing: | |
# - HTTPS support | |
# - Saved credential access | |
# - Error handling | |
# - Pre-warming of basic auth | |
# - Progress bar | |
# - Package state | |
# - Removal | |
# - ... | |
function Publish-HololensAppx | |
{ | |
param( | |
[Parameter(Mandatory=$true)] [string] $DeviceAddress, | |
[Parameter(Mandatory=$true)] [string] $AppX, | |
$Credential = (Get-Credential) | |
) | |
Write-Host "Uploading $AppX" | |
Add-Type -AssemblyName System.Net.Http | |
$AppXFileName = [System.IO.Path]::GetFileName($AppX); | |
$PublishUri = "http://$DeviceAddress/api/app/packagemanager/package?package=$AppXFileName" | |
$HttpClientHandler = New-Object System.Net.Http.HttpClientHandler | |
$HttpClientHandler.Credentials = New-Object System.Net.NetworkCredential @($Credential.UserName, $Credential.Password) | |
$HttpClient = New-Object -TypeName System.Net.Http.HttpClient $HttpClientHandler | |
$AppxFileStream = New-Object -TypeName System.IO.FileStream @($AppX, [System.IO.FileMode]::Open) | |
$AppxStreamContent = New-Object -TypeName System.Net.Http.StreamContent $AppxFileStream | |
# | |
# HACK: Device Portal doesn't seem to support quoted-string boundary values (against rfc2045) | |
# so we have to build a boundary ourselves. | |
# feedback-hub:?contextid=519&feedbackid=19a5af49-38f4-409a-b464-e66f80679545&form=1&src=2 | |
# | |
$Content = New-Object -TypeName System.Net.Http.MultipartFormDataContent "__Boundary" | |
$Content.Headers.Remove("Content-Type") | Out-Null | |
$Content.Headers.Add("Content-Type", "multipart/form-data; boundary=__Boundary") | |
# | |
# HACK: Device Portal doesn't seem to support *non*-quoted-string values for the name/filename | |
# disposition attributes (against rfc2183) so we have to hack quotes in | |
# feedback-hub:?contextid=519&feedbackid=fc230a20-209f-4435-9717-56218674f9af&form=1&src=2 | |
# | |
$Content.Add($AppxStreamContent, """$AppXFilename""", """$AppXFileName""") | |
$HttpClient.Timeout = [Timespan]::FromMinutes(5) | |
$HttpClient.PostAsync($PublishUri, $Content).Result | |
Write-Host "Done." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment