Cách đóng gói phần mềm c# visual studio 2017

     

Xin chào những bạn, bài viết hôm ni mình đang hướng dẫn các bạn đóng gói phần mềm thành file thiết lập installer áp dụng script PowerShell.Bạn sẽ xem: Đóng gói ứng dụng thành tệp tin exe

Sau khi chúng ta viết xong phần mượt trên Winform, các bạn cần phải đóng gói phần mềm thành file cài đặt đặt.

Bạn đang xem: Cách đóng gói phần mềm c# visual studio 2017

Bình thường, các bạn sẽ sử dụng phần mềm: Advance Installer, One Click Install tuyệt Installshield...

Trong nội dung bài viết này mình sẽ hướng dẫn các bạn đóng gói áp dụng tool bé dại cài đặt thực hiện script PowerShell.

Lợi ích của bài toán đóng gói này là file thiết lập của bạn khoảng 300MB (nếu các bạn nào code bởi Devexpress thì vẫn thấy dung tích rất nhiều).

Nhược điểm: Muốn thiết lập phải tất cả mạng internet.

Xem thêm: Hướng dẫn đăng ký AE888, trang chủ cá cược chính thức AE888

Các chúng ta có thể mở lịch trình Powershell ISE, để code script


*

Các bước đóng gói phần mềm SVG Collection của mình.

Bước 1: Nén File vận dụng ở thư mục Release lên hosting web của các bạn

Và khi chạy Script mua đặt bọn họ sẽ thực hiện các bước công bài toán sau:

Bước 2: download file tự hosting name VD: https://bdkhtravinh.vn/svg_csharp.rar 

Bước 3: Giải nén file rar vào thư mục họ chỉ định

Bước 4: Xóa file rar chúng ta đã thiết lập về

Bước 5: Chạy mở vận dụng lên

Bước 6: chế tạo ra shortcut ứng dụng trước Desktop.

Script mình viết cũng 1-1 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, chúng ta sẽ thực hiện PS2EXE => gửi file script thành file EXE

Video demo ứng dụng tạo sau khoản thời gian tạo 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 ứng dụng Powershell - https://bdkhtravinh.vn"Add-Type -AssemblyName System.Windows.Forms$browser = New-Object System.Windows.Forms.FolderBrowserDialog$browser.Description = "Bạn nên chọn lựa thư mục thiết lập phần mềm"$null = $browser.ShowDialog()$temp = $browser.SelectedPathWrite-Output $temp$url = "https://bdkhtravinh.vn/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 tải $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 tải ứ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." -ForegroundColor DarkGreen; $destStream.Flush() $destStream.Close() $destStream.Dispose() $responseStream.Dispose()Get-Webfile $urlWrite-Output "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-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-Output -Verbose "$RarFileTargetCount RAR files have been extracted" $NewLine Else $NewLine Write-Warning -Message "$RarFileTargetCount out of $RarFileSourceCount have been extracted" $NewLine kết thúc 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-Output -Verbose 'Deleting source RAR files & 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 to lớn exist..."#::ReadKey($true)Sau khi tạo thành script kết thúc để biên dịch tệp tin script thành file EXE các bạn vào đường dẫn github PS2EXE sau để xem chi tiết tạo tệp tin setup.

https://github.com/MScholtes/PS2EXE

Bước 1: chúng ta mở công tác PowerShell lên

Bước 2: Gõ lệnh cài PS2EXE về

PS C:> Install-Module ps2exeBước 3: Lệnh đóng góp gói, các bạn chỉ chọn băng thông file script với file xuất exe

Invoke-ps2exe .source.ps1 .arget.exeKhi build file Exe, nếu như các bạn muốn chỉnh sửa các tham số Assembly giỏi icon của ứng dụng, khi build các bạn làm theo cú pháp bên dưới:

qqlive| j88