Reputation: 3518
I have some methods that need to run once per build of my web application, and not more (and not even once per application startup). The simplest way I have imagined doing this is to save a "LastBuildID" to a database, and upon each application startup, compare the "CurrentBuildID" to the last one saved in the database. If the two Build IDs are different, then it's a new build, and the methods should run.
The code would look something like this:
public static void RunIfNewBuild()
{
var CurrentBuildID = ??? //what should I put here?
var LastBuildID = DatabaseContext.GetKey("LastBuildID");
if (CurrentBuildID != LastBuildID)
{
DatabaseContext.SetKey("LastBuildID", CurrentBuildID);
Method1();
Method2();
Method3();
}
}
So, can I access some sort of unique ID or GUID that is unique to the current build of the application? I'm using C# with Asp.NET Core 3.1.
Upvotes: 2
Views: 754
Reputation: 794
Get it from assemble info like this. It will change when your code changes.
var CurrentBuildID = Assembly.GetExecutingAssembly().ManifestModule.ModuleVersionId;
Upvotes: 3