Xin kính chào các bạn, bài viết lúc này mình sẽ lí giải các bạn đóng gói phần mềm thành tệp tin thiết đặt installer áp dụng script PowerShell.
Bạn đang xem: Đóng gói phần mềm thành file exe
Sau Khi các bạn viết dứt phần mềm trên Winform, những bạn cần phải đóng gói ứng dụng thành file cài đặt.
Bình hay, những bạn sẽ sử dụng phần mềm: Advance Installer, One Cliông xã Install xuất xắc Installshield...
Trong bài viết này mình sẽ lý giải các bạn gói gọn vận dụng tool nhỏ tuổi thiết đặt sử dụng script PowerShell.
Lợi ích của vấn đề đóng gói này là tệp tin cài đặt của người tiêu dùng khoảng chừng 300MB (nếu khách hàng như thế nào code bằng Devexpress thì vẫn thấy dung tích rất nhiều).
lúc thiết đặt build thì tệp tin Exe họ chỉ với khoảng tầm khoảng 300KB, góp họ dễ dãi phân chia đang.
Xem thêm: Từ Vựng Tiếng Anh Về Các Loại Hạt Điều Tiếng Anh Là Gì ? Hạt Điều Tiếng Anh Là Gì
Nhược điểm: Muốn nắn thiết đặt buộc phải gồm mạng mạng internet.
Các chúng ta có thể msinh hoạt chương trình Powershell ISE, để code script
Các bước gói gọn ứng dụng SVG Collection của bản thân mình.
Cách 1: Nén File ứng dụng nghỉ ngơi thỏng mục Release lên hosting website của những bạn
Và Khi chạy Script setup bọn họ vẫn tiến hành các bước công việc sau:
Bước 2: Download tệp tin từ bỏ hosting name VD: https://balkanpoliticalclub.net/svg_csharp.rar
Cách 3: Giải nén file rar vào tlỗi mục chúng ta chỉ định
Cách 4: Xóa File rar bọn họ đang download về
Bước 5: Chạy msinh sống áp dụng lên
Bước 6: Tạo shortcut ứng dụng trước Desktop.
Script bản thân viết cũng dễ dàng và đơn giản các bạn chỉ cần vào sửa đổi các thông số lại là xong nhé.
Sau khi Viết Script PowerShell xong, bọn họ vẫn sử dụng PS2EXE => chuyển tệp tin script thành tệp tin EXE
Video kiểm tra ứng dụng sản xuất sau thời điểm chế tác tệp tin thiết lập thành công:
Source code full script PowerShell setup:
::InputEncoding = ::OutputEncoding = New-Object System.Text.UTF8Encoding$host.UI.RawUI.WindowTitle = "Cài đặt ứng dụng Powershell - https://balkanpoliticalclub.net"Add-Type -AssemblyName System.Windows.Forms$browser = New-Object System.Windows.Forms.FolderBrowserDialog$browser.Description = "Quý Khách Hãy chọn tlỗi mục thiết lập phần mềm"$null = $browser.ShowDialog()$temp = $browser.SelectedPathWrite-đầu ra $temp$url = "https://balkanpoliticalclub.net/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-Webfile ($url) $dest = $output Write-Host "Đang sở hữu $url`n" -ForegroundColor 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 Where-Object -FilterScript $_.extension -eq '.rar' ).FullName $RarFileSourceCount = $RarFilePaths.Count Process $NewLine Write-Output -Verbose "Total RAR File Count: $RarFileSourceCount" $NewLine Write-đầu ra -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-Output -Verbose "$RarFileTargetCount RAR files have 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 -Verbose 'Opening RAR target location...' Start-Sleep -Seconds 5 Invoke-Item -Path $UnRarTargetPath $_ -contains 'DeleteSourceRarFiles' $NewLine Write-đầu ra -Verbose 'Deleting source RAR files và 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-Output "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 khổng lồ exist..."#::ReadKey($true)Sau Lúc tạo ra script ngừng nhằm biên dịch File script thành File EXE các bạn vào đường truyền github PS2EXE sau giúp xem cụ thể tạo file thiết đặt.
https://github.com/MScholtes/PS2EXE
Bước 1: Các các bạn msinh hoạt chương trình PowerShell lên
Cách 2: Gõ lệnh cài đặt PS2EXE về
PS C:> Install-Module ps2exeCách 3: Lệnh gói gọn, các bạn chỉ lựa chọn đường dẫn file script và file xuất exe
Invoke-ps2exe .source.ps1 .arget.exeKhi build File Exe pháo, trường hợp các bạn muốn chỉnh sửa những tmê mệt số Assembly xuất xắc inhỏ của ứng dụng, Lúc build các bạn làm theo cú pháp bên dưới: