[英]Write an executable application in windows
我想寫一個工具來部署我的應用程序,基本上這個東西需要兩部分:
web.config
文件之外的所有內容現在這個問題我只想完成第一個問題,我們一直在手動部署,所以我想提高我的效率。
這是我的想法。 我基本上有兩個想法:
web.config
之外的所有內容我更喜歡第二個,因為腳本不會那么難調整,而且也很簡單。
我的問題是:如果我想寫這個腳本,我應該如何開始呢? 就像那種文件,你點擊它,你會看到一個黑色的 window DOS 屏幕,然后你輸入運行,然后這些文件夾中的所有內容都將消失。 有人可以給我一個起點嗎?
非常感謝!
您可能可以制作一個簡單的控制台應用程序來復制 bin 文件夾中的所有內容(Release 或 Debug)並覆蓋應用程序工件(減去配置文件)。 這基本上是 Team City、AzureDevOps 和許多其他 DevOps 工具所做的。 但是,在后台,他們使用 powershell。 如果您的應用程序在替換您的應用程序工件之前沒有任何需要停止的服務,您可以使用類似下面的內容。 如果您需要停止和啟動服務,這也很簡單,前提是您有權這樣做。 這可以編譯成可執行文件,或保存為 .ps1 文件。 Either one can be ran from Powershell (Invoke-Item command or right click and run with Powershell), or in command window ( https://www.howtogeek.com/674537/how-to-find-and-open-files-使用命令提示符/ )
# If you need to stop services
Get-Service -Name $serviceName -ComputerName $computerName | Set-Service -Status Stopped;
# Variables
$folder = "C:\CODE\ApplicationFolder\Web\bin\Release"
$webConfig = "WebConfig.exe.config"
$destinationPath = "\\serverName\folderPath\"
$destinationFolder = "Release"
# Zip existing folder and rename for backup
Compress-Archive -Path $destinationPath -DestinationPath $destinationPath\ApplicationArtifacts_Backup_$(Get-Date -Format MMddyyyy).zip | Out-Default
# Get Updated application deployment artifacts
Copy-Item -Path $folder\* -Exclude $webConfig -Destination $destinationPath$destinationFolder -Recurse -Force | Out-Default
# If you need to start services
Get-Service -Name $serviceName -ComputerName $computerName | Set-Service -Status Running;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.