What's the best way to deploy an executable pr

2020-05-20 03:15发布

The original question:

The title of this question might be a bit clumsily phrased, but here's the situation:

I have a .NET web project deployed on my server. It's still in beta, so there's a lot of releasing and re-releasing happening.

I have also written a C# executable in the same VS solution (call it "admin.exe") that runs in the background on the server, periodically performing certain business rule integrity checks and making appropriate insertions to a warning table in the DB.

Question is: what's the best way to deploy this app so that it gets updated whenever I make a new release? It should be running all the time in between releases, so ideally I'd like some sort of setup whereby the shutdown-deploy-startup process involves the minimum possible number of steps.

Thanks!

Edit - Bounty started

The answers given thus far have been helpful and interesting, but haven't provided me with a clear, concise and elegant solution. Please do not assume I have extensive knowledge of deployment projects, because I don't. Bounty goes to the person who can provide a solution that does the following:

  1. Publish the latest version of the web site;
  2. Shut down any instances of admin.exe that are running on the server;
  3. Update admin.exe;
  4. Launch admin.exe;
  5. All of the above should be done preferably in one step, or as few steps as possible, seeing as it will be done repeatedly throughout the life of the product; and
  6. All of the above should be done preferably without requiring installation of any 3rd party software.

Thank you for your help!

Minor edit - clarification

I think a lot of the solutions offered thus far have overestimated the complexity of the problem, so let me clarify: everything that is to be deployed, only has to be deployed on one computer, which also happily has Visual Studio available with all source code. I only need to (1) publish the web site to the web folder, and (2) shut down, reinstall and restart admin.exe on the same server. Isn't there a simple way of doing this in one step? Can it be done with a VS Deployment project?

11条回答
地球回转人心会变
2楼-- · 2020-05-20 03:23

Store on the server/web the most recent version of the project that is online. eg: in a version.txt the value "2.1.0", or query the database if you have access too.

Your application running on clients, will periodically read the contents of the version.txt file, then compared against the inbuilt(self) version number.

  • If a patch or minor release is detected eg 2.1.123, spins out a second app(updater.exe) that will quietly
    • do the upgrade,
    • it shall download the updated(preferred zipped) project from server/web.
    • Stop any running instances.
    • Unzipping the content.
    • Backup existing files(rename)
    • copy/install the new version of the project,
    • Start the application (when the app is restarted successfully it will delete its own backup file).
  • if a major release is detected eg: 3.0.0
    • notifies the user there is a major upgrade
    • if user accepts, download the installer
    • runs a full installer update

Does this help?

查看更多
Anthone
3楼-- · 2020-05-20 03:31

There is probably a much cleaner way but maybe install it as a windows service then script the install / uninstall commands using installutil.exe. Then just update the folder where the service sits and re-run the script for each update?

Great service tutorial here

Hope this helps

查看更多
姐就是有狂的资本
4楼-- · 2020-05-20 03:31

In order to make things simple and make sure I would be able to roll back everything, I would create a PowerShell Script that performed the following actions:

  1. Stop the Application Pool.
  2. Copy the current web app to the "history folder" so you can rollback to that version if required
  3. Deploy the new web app
  4. Stop the current admin.exe from services
  5. Uninstall the admin.exe, by executing the Uninstall.bat (this is quite common for Windows Services)
  6. Copy the current admin.exe app to the history folder (see 2)
  7. Copy the new admin.exe to the correct location and run install.bat
  8. Start the new service
  9. Start the application Pool

You can automate all of that in a Powershell script (the only thing I'm not sure is about the app pool, but I'm pretty sure that you can do this).

More info on PowerShell can be found here: http://arstechnica.com/business/news/2005/10/msh.ars/2

查看更多
5楼-- · 2020-05-20 03:34

VS Deployment project for a web app is not that easy to master and somewhat not reliable. What I'd suggest:

  1. Modify your Admin.exe into a .NET Windows service. Seebelow why would you need to do it.
  2. Use sc.exe, InstallUtil.exe or installer-building services like installer.codeeffects.com to reinstall your service fast on every deployment. Btw, if I remember correctly, at installer.codeeffects.com you can download a VS example code of how to build a .NET Windows service if you're new to services.

Deployment could be done like this (assuming that your needs in automation is minimal and you're fine deploying almost manually):

Run either of the above mentioned tools to reinstall your service first. The sc.exe and InstalUtil.exe tools support command line. Therefore, if your web app, VS and the service is running on the same machine (your development computer, I assume?), you can right-click the web project in VS, select Properties and set pre- or post-build commands in the Build Events tab there. This way your VS can automatically rebuild and reinstall your service before you publish your web app. This is the main reason why the exe program is not good in your case, a Windows service would serve you better.

Then deploy your web app (assuming it's been build as discussed above). No biggies here, just use the Publish command from your VS or move all files of your web app except for the .cs files, /Properties/ and /obj/ folders. Or, if running from the project's folder, just right click the main page and select "View in Browser" - this will start the run time through VS without starting the debugger.

Sorry for such a lengthy post. Did I understand your question and clarifications correctly? :)

查看更多
够拽才男人
6楼-- · 2020-05-20 03:35

Here's a nasty thought. If you're admin.exe isn't doing anything too hard core, why not throw into IIS? To write a C# Web Service, you probably won't need to change much.

To ensure it gets called repeatedly, you could use any variety of methods, like Windows Scheduler to run wget once a minute. Keep concurrent copies from running with a file lock, should it ever take MORE than one minute to complete.

This would make your deployment as simple as a file copy (FTP). I don't even think you need to reboot IIS when pushing a C# DLL. If you do, you can script that up over SSH.

查看更多
兄弟一词,经得起流年.
7楼-- · 2020-05-20 03:35

What about making admin.exe a click once deployment. Then in your admin.exe, before you check the integrity of business rules, check if an update is available. If it is, update and then continue on with your checks.

查看更多
登录 后发表回答