简体   繁体   English

应用程序部署后在 StartUp.cs 中只运行一次函数

[英]Run a function just once in StartUp.cs After application Deployment

I am developing ASP.NET core 2.2 web application.我正在开发 ASP.NET 核心 2.2 Web 应用程序。 I want to run a function just once after the application is deployed each time in Startup.cs file.我想在每次在 Startup.cs 文件中部署应用程序后只运行一次函数。

This function slows down the application as it does some heavy checks on the application startup.此功能会减慢应用程序的速度,因为它会对应用程序启动进行一些繁重的检查。 I only want to run this just once each time when the application is deployed.每次部署应用程序时,我只想运行一次。

This is the code这是代码


SynapseCore.Services.Plugins.SiteContentDiscovery iCont = new SiteContentDiscovery();
            _logger.LogInformation("Startup - Complete : SiteContentDiscovery", new object[0]);

            SynapseCore.Shared.GlobalData.pluginList = pluginsInfoList;
            _logger.LogInformation("Startup - Complete : pluginList", new object[0]);

            iCont.SetPluginInfo(pluginsInfoList);
            _logger.LogInformation("Startup - Complete : SetPluginInfo", new object[0]);

        //The following function 'CheckDatabaseIntegrity' is to be run once after deployment. 
           iCont.CheckDatabaseIntegrity();
          _logger.LogInformation("Startup - Complete : CheckDatabaseIntegrity", new object[0]);

            iCont.CheckPluginStatus();
            _logger.LogInformation("Startup - Complete : CheckPluginStatus", new object[0]);

            PluginSiteComposedData composedData = iCont.CompileSiteDataList();

I have looked into我已经调查过

Environment.GetEnvironmentVariables() 

But doesn't seem to have that attribute i am looking for.但似乎没有我正在寻找的属性。

My question is, how do i detect through code if the application is running for the first time after deployment on IIS ?我的问题是,如果应用程序在 IIS 上部署后第一次运行,我如何通过代码检测?

You could simply store and check the assembly version.您可以简单地存储和检查程序集版本。 If it increased you can assume that you deployed a new version.如果它增加了,您可以假设您部署了一个新版本。

But you also have to increase it in your project properties each time you want to deploy a new version.但是每次要部署新版本时,您还必须在项目属性中增加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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