Моя текущая реализация для истечения версии всегда говорит, что дата публикации недействительна.
Я использую. />
WinExe
net5.0-windows
true
Always
< /code>
Здесь я проверяю встроенную дату, которая должна вернуть дату сборки. < /p>
private DateTime GetBuildDate()
{
// Read build date from embedded resource or file
var buildDateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "builddate.txt");
if (File.Exists(buildDateFile))
{
var dateStr = File.ReadAllText(buildDateFile).Trim();
if (DateTime.TryParse(dateStr, out var date))
return date;
}
// Fallback to assembly creation time
return File.GetCreationTime(Assembly.GetExecutingAssembly().Location);
}
//public const string BuildDate = "$(BuildDate)";
//public const string BuildDate = BuildInfo.BuildDate;
public async Task CheckVersionExpiryAsync()
{
var age = DateTime.Now - _buildDate;
if (age.TotalDays > MAX_VERSION_AGE_DAYS)
{
var result = MessageBox.Show(
$"This version of the application has expired ({age.Days} days old).\n\n" +
$"Maximum allowed age: {MAX_VERSION_AGE_DAYS} days.\n\n" +
"Would you like to check for updates now?",
"Version Expired",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
await CheckForUpdatesAsync(true);
}
return false;
}
return true;
//var age = DateTime.Now - DateTime.Parse(BuildDate);
/*DateTime bDate;
if (DateTime.TryParseExact(BuildDate, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out bDate))
{
if (DateTime.UtcNow > bDate.AddMonths(2))
{
var age = (DateTime.UtcNow - bDate).Days;
var result = MessageBox.Show(
$"This version of the application has expired ({age/*.Days} days old).\n\n" +
$"Maximum allowed age: {MAX_VERSION_AGE_DAYS} days.\n\n" +
"Would you like to check for updates now?",
"Version Expired",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
await CheckForUpdatesAsync(true);
}
return false;
}
return true;
}
else
{
MessageBox.Show("Invalid data", "ID1 Error", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}*/
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... wpf-on-net