简体   繁体   English

在 windows 中编写一个可执行应用程序

[英]Write an executable application in windows

I want to write a tool to deploy my application, basically this thing need 2 parts:我想写一个工具来部署我的应用程序,基本上这个东西需要两部分:

  1. Delete everything inside a folder except for the web.config file删除文件夹中除web.config文件之外的所有内容
  2. Transfer everything inside a folder into another folder将文件夹中的所有内容转移到另一个文件夹中

Right now, in this question I just want to complete the first one, we do manual deployment all the time, therefore I want to enhance my efficiency.现在这个问题我只想完成第一个问题,我们一直在手动部署,所以我想提高我的效率。

Here is my thought.这是我的想法。 I have basically two thoughts:我基本上有两个想法:

  1. Write an application in Visual Studio, maybe in C#, and then enter the folder name, set something in the code where deleting everything except web.config在 Visual Studio 中编写一个应用程序,可能在 C# 中,然后输入文件夹名称,在代码中设置一些内容,删除除web.config之外的所有内容
  2. Write a simple script that I can just run it in the cmd, and just execute it.编写一个简单的脚本,我可以在 cmd 中运行它,然后执行它。

I prefer the second one, since a script won't be that hard to adjust and is going to be simple as well.我更喜欢第二个,因为脚本不会那么难调整,而且也很简单。

My question is: if I want to write this script, how should I start it?我的问题是:如果我想写这个脚本,我应该如何开始呢? Is like those kind of file you click it and you will have a black window DOS screen and you type in run then all of the content inside those folder will be gone.就像那种文件,你点击它,你会看到一个黑色的 window DOS 屏幕,然后你输入运行,然后这些文件夹中的所有内容都将消失。 Can someone gives me a starting point?有人可以给我一个起点吗?

Much appreciate!非常感谢!

You could probably make a simple console app to copy everything from your bin folder (Release or Debug) and overwrite the application artifacts (minus the config file).您可能可以制作一个简单的控制台应用程序来复制 bin 文件夹中的所有内容(Release 或 Debug)并覆盖应用程序工件(减去配置文件)。 This is essentially what Team City, AzureDevOps, and a number of other DevOps tools do.这基本上是 Team City、AzureDevOps 和许多其他 DevOps 工具所做的。 However, in the background, they use powershell.但是,在后台,他们使用 powershell。 If your application does not have any services that need to be stopped before replacing your applications artifacts, you could use something like the below.如果您的应用程序在替换您的应用程序工件之前没有任何需要停止的服务,您可以使用类似下面的内容。 If you need to stop and start services, that is pretty simple as well, assuming you have permissions to do so.如果您需要停止和启动服务,这也很简单,前提是您有权这样做。 This can be compiled into an executable, or saved as a.ps1 file.这可以编译成可执行文件,或保存为 .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-using-command-prompt/ ) 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM