upgrade - Wixsharp 升级不保留以前的设置,如数据库数据和其他配置
问题描述
我正在使用 wixsharp 构建我的安装程序。每次我提供一个新版本时,我都想更新我的所有 exe、dll 和其他二进制文件,但我想保留手动更改的设置,例如我们可以选择将一些密钥存储在数据库中,这将在程序文件的应用程序文件夹中创建一些文件夹。我想保留这些数据并替换二进制文件,但是当我升级时它也会删除这些数据。
我正在使用下面的 wixsharp 代码来实现升级。
project.UpgradeCode= new Guid("some GUID here, keeping it same in all builds");
project.ProductId = new Guid("GUID here, changing it in all incremental build");
project.Version = new Version(6, 1, 1, 1); // upgrading it in incremental builds
project.MajorUpgrade = new MajorUpgrade
{
Schedule = UpgradeSchedule.afterInstallValidate,
AllowSameVersionUpgrades = true,
MigrateFeatures =true,
IgnoreRemoveFailure=true,
DowngradeErrorMessage="A new version of this product is already installed."
};
我面临的另一个问题是,当我们安装第二个版本时,它没有显示升级选项,而只显示安装选项(如全新安装),最后它要求用户允许卸载产品,即卸载旧产品看起来,但它看起来对用户不友好,因为用户可能会觉得他/她为什么要卸载产品。我只想要一个升级选项,它可以在不向用户显示后端发生的情况下进行升级。
解决方案
问题一:
如果您想拥有一些静态文件,如果不存在则添加这些文件,但不使用新的安装更新它们。您需要使用Permanent="yes" NeverOverwrite="yes"属性标记它们。
更多信息链接在这里:Wix Component Element
如何用 WixSharp 制作它?
这是我的代码如何使 index.html 和 web.config 不可变:
var immutableFiles =
{
@"index.html",
@"web.config"
};
// ....
var wixObjects = new WixObject[]
{
new Dir(
@"%ProgramFiles%\YourProductFolderName\",
WixFilesBuilderUtils.BuildDirectoryInfo(BinariesRoot, immutableFiles)),
// Properties etc...
}.ToArray();
var project = new ManagedProject("name", wixObjects);
生成器代码:
public class WixFilesBuilderUtils
{
public static WixEntity[] BuildDirectoryInfo(string currentRoot, IEnumerable<string> immutableFiles)
{
var result = new List<WixEntity>();
var currentRootDictionaryInfo = new DirectoryInfo(currentRoot);
var localImmutableFiles = immutableFiles.Select(fileName => fileName.ToLower()).ToArray();
var currentRootDirList = currentRootDictionaryInfo
.GetDirectories()
.Select(dirInfoSub => dirInfoSub.FullName).ToArray();
result.AddRange(
Directory.GetFiles(currentRootDictionaryInfo.FullName)
.Select(
filePath => new WixSharp.File(filePath)
{
Attributes = MarkFileAsPersonal(filePath, localImmutableFiles)
})
.Cast<WixEntity>());
if (currentRootDirList.Any())
{
var subDirs = currentRootDirList
.Select(dirPath => new DirectoryInfo(dirPath))
.Select(
rootSubDirInfo =>
new Dir(rootSubDirInfo.Name,
BuildDirectoryInfo(rootSubDirInfo.FullName, localImmutableFiles)))
.Cast<WixEntity>();
result.AddRange(subDirs);
}
return result.ToArray();
}
private static Dictionary<string, string> MarkFileAsPersonal(string path, IEnumerable<string> immutableFiles)
{
return immutableFiles.Any(path.ToLower().EndsWith)
? new Dictionary<string, string>
{
{ "Component:Permanent", "yes" },
{ "Component:NeverOverwrite", "yes" }
}
: new Dictionary<string, string>();
}
}
问题2:
请尝试使用相同的 UpdateCode 和 ProductCode GUID,每个构建和这一策略:
MajorUpgradeStrategy = new MajorUpgradeStrategy
{
RemoveExistingProductAfter = Step.InstallInitialize,
UpgradeVersions = VersionRange.OlderThanThis,
PreventDowngradingVersions = VersionRange.NewerThanThis,
NewerProductInstalledErrorMessage = "."
};
推荐阅读
- flutter - 如何在导航上处理父小部件的同级
- android - 全屏对话框示例中 Android 的过渡动画
- excel - 满足条件时遍历数组元素并提取分隔值
- html - 在轮播中获取适当大小的品牌徽标
- android - 两个Android进程是否可以具有相同的名称?
- regex - 如何将正则表达式匹配到文本文件?
- elasticsearch - Elasticsearch 让用户赢得拍卖(用户出价最高的地方)——就像在 SQL 中一样
- html - 移动 Safari 中的 SVG 渲染更小
- arrays - 将升序数组排序转换为降序 VBA
- python - TypeError:尝试调整图像大小时,“pygame.Surface”对象不可调用