Xin chào chúng ta, nội dung bài viết từ bây giờ mình đã gợi ý các bạn gói gọn phần mềm thành tệp tin cài đặt installer áp dụng script PowerShell.
Bạn đang xem: Đóng gói phần mềm thành file exe
Sau Lúc các bạn viết chấm dứt phần mềm trên Winsize, những bạn cần phải đóng gói phần mềm thành tệp tin setup.
Bình thường xuyên, những bạn sẽ áp dụng phần mềm: Advance Installer, One Cliông chồng Install xuất xắc Installshield...
Trong nội dung bài viết này mình vẫn khuyên bảo các bạn đóng gói áp dụng tool nhỏ tuổi thiết lập sử dụng script PowerShell.
Lợi ích của vấn đề gói gọn này là tệp tin cài đặt của khách hàng khoảng 300MB (nếu như bạn làm sao code bởi Devexpress thì đã thấy dung tích khôn cùng nhiều).
Khi setup build thì tệp tin Exe chúng ta chỉ với khoảng trung bình 300KB, góp bọn họ thuận tiện chia sẽ.
Xem thêm: Rạp Cgv Vivo City Tphcm: Địa Chỉ, Giá Vé, Lịch Chiếu, Cgv Vivo City
Nhược điểm: Muốn cài đặt yêu cầu tất cả mạng internet.
Các chúng ta cũng có thể msinh sống công tác Powershell ISE, để code script
Các bước gói gọn ứng dụng SVG Collection của chính mình.
Cách 1: Nén File ứng dụng ở thư mục Release lên hosting website của các bạn
Và Khi chạy Script setup chúng ta đang tiến hành quá trình các bước sau:
Bước 2: Download file từ bỏ hosting name VD: https://sydneyowenson.com/svg_csharp.rar
Bước 3: Giải nén tệp tin rar vào thư mục chúng ta chỉ định
Cách 4: Xóa File rar bọn họ đang sở hữu về
Bước 5: Chạy mnghỉ ngơi áp dụng lên
Cách 6: Tạo shortcut ứng dụng trước Desktop.
Script mình viết cũng dễ dàng và đơn giản chúng ta chỉ việc vào sửa đổi những thông số kỹ thuật lại là dứt nhé.
Sau lúc Viết Script PowerShell xong, bọn họ đã sử dụng PS2EXE => đưa tệp tin script thành tệp tin EXE
Video demo áp dụng chế tạo ra sau thời điểm chế tạo ra file setup thành công:
Source code full script PowerShell setup:
::InputEncoding = ::OutputEncoding = New-Object System.Text.UTF8Encoding$host.UI.RawUI.WindowTitle = "Cài đặt phần mềm Powershell - https://sydneyowenson.com"Add-Type -AssemblyName System.Windows.Forms$browser = New-Object System.Windows.Forms.FolderBrowserDialog$browser.Description = "Quý khách hàng Hãy chọn thỏng mục cài đặt phần mềm"$null = $browser.ShowDialog()$temp = $browser.SelectedPathWrite-Output $temp$url = "https://sydneyowenson.com/svg_csharp.rar"$output = $temp + "svg_csharp.rar"$start_time = Get-Date#Import-Module BitsTransfer#Start-BitsTransfer -Source $url -Destination $output#OR#Start-BitsTransfer -Source $url -Destination $output -AsynchronousFunction Get-Webtệp tin ($url) $dest = $output Write-Host "Đang cài đặt $url`n" -Foregroundmàu sắc DarkGreen; $uri=New-Object "System.Uri" "$url" $request=::Create($uri) $request.set_Timeout(5000) $response=$request.GetResponse() $totalLength=::Floor($response.get_ContentLength()/1024) $length=$response.get_ContentLength() $responseStream=$response.GetResponseStream() $destStream=New-Object -TypeName System.IO.FileStream -ArgumentList $dest, Create $buffer=New-Object byte<> 10KB $count=$responseStream.Read($buffer,0,$buffer.length) $downloadedBytes=$count while ($count -gt 0) ::CursorLeft = 0 ::Write("Đang download ứng dụng 0K of 1K (2%)", ::Floor($downloadedBytes/1024), $totalLength, ::Round(($downloadedBytes / $length) * 100,0)) $destStream.Write($buffer, 0, $count) $count=$responseStream.Read($buffer,0,$buffer.length) $downloadedBytes+=$count Write-Host "" Write-Host "`nDownload of `"$dest`" finished." -ForegroundMàu sắc DarkGreen; $destStream.Flush() $destStream.Close() $destStream.Dispose() $responseStream.Dispose()Get-Webfile $urlWrite-Output đầu ra "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"Set-Location $tempFunction Extract-WinRarFiles Param ( $UnRarExePath = "$env:ProgramFilesWinRARUnRAR.exe", $UnRarSourcePath, $UnRarTargetPath, $OpenTargetLocation, $DeleteSourceRarFiles ) Begin $NewLine = "`r`n" $RarFilePaths = (Get-ChildItem -Path $UnRarSourcePath -Recurse Process $NewLine Write-Output -Verbose "Total RAR File Count: $RarFileSourceCount" $NewLine Write-Output -Verbose "Beginning extraction, please wait..." Start-Sleep -Seconds 2 Foreach ($FilePath in $RarFilePaths) &$UnRarExePath x -y $FilePath $UnRarTargetPath $RarFileTargetCount = (Get-ChildItem -Path $UnRarTargetPath).Count If ($RarFileTargetCount -eq $RarFileSourceCount) Clear-Host $NewLine Write-đầu ra -Verbose "$RarFileTargetCount RAR files have sầu been extracted" $NewLine Else $NewLine Write-Warning -Message "$RarFileTargetCount out of $RarFileSourceCount have been extracted" $NewLine End Switch ($PSBoundParameters.Keys) $_ -contains 'OpenTargetLocation' $NewLine Write-Output đầu ra -Verbose 'Opening RAR target location...' Start-Sleep -Seconds 5 Invoke-Item -Path $UnRarTargetPath $_ -contains 'DeleteSourceRarFiles' $NewLine Write-Output -Verbose 'Deleting source RAR files and the directory...' Start-Sleep -Seconds 5 Remove-Item -Path $UnRarSourcePath -Recurse -Force Set-Location $temp$appPath = $temp + "SGV Collection.exe" Extract-WinRarFiles -UnRarSourcePath $output -UnRarTargetPath $temp -DeleteSourceRarFiles Write-đầu ra "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" Remove-Item *.tmp -recurse -force Start-Process -FilePath $appPath $WshShell = New-Object -comObject WScript.Shell$Shortcut = $WshShell.CreateShortcut("$HomeDesktopSGV Collection.lnk")$Shortcut.TargetPath = $appPath$Shortcut.Save()write-host "Setup finish..."write-host "Press any key lớn exist..."#::ReadKey($true)Sau lúc tạo nên script dứt nhằm biên dịch File script thành File EXE các bạn vào đường truyền github PS2EXE sau để xem chi tiết tạo thành tệp tin thiết đặt.
https://github.com/MScholtes/PS2EXE
Bước 1: Các chúng ta mnghỉ ngơi chương trình PowerShell lên
Bước 2: Gõ lệnh cài đặt PS2EXE về
PS C:> Install-Module ps2exeBước 3: Lệnh đóng gói, chúng ta chỉ lựa chọn băng thông tệp tin script cùng tệp tin xuất exe
Invoke-ps2exe .source.ps1 .arget.exeLúc build File Exe pháo, nếu như các bạn muốn chỉnh sửa các tđắm say số Assembly xuất xắc icon của vận dụng, Khi build chúng ta tuân theo cú pháp bên dưới: