I have an asp net core api.
I want to run a function only once after a publish will convert and resize all images to a more lightweight version.
The problem I have is I want this function to run only once. I can't find a way to do that.
I have an asp net core api.
I want to run a function only once after a publish will convert and resize all images to a more lightweight version.
The problem I have is I want this function to run only once. I can't find a way to do that.
If you want to call function from your program, it could not be achieved by cutsom publish process.
For a workaround, you may try implement the requirement like seeding data to database.
var host = BuildWebHost(args);
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
//check whether the images has been resized
//if not, call function to resize.
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred seeding the DB.");
}
}
host.Run();
Or, you could try implement a middleware to check whether the images has been resized.