Вопрос 1:
Если вы хотите иметь несколько файлов * stati c, которые добавляются, если они не существуют, но не обновляют их новой установкой. Вам нужно пометить их Permanent = "yes" NeverOverwrite = "yes" атрибутов.
Для получения дополнительной информации ссылка здесь: Элемент Wix Component
Как сделать это с 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:
Пожалуйста, попробуйте использовать одинаковые GUID UpdateCode и ProductCode для каждой сборки и этой одной стратегии:
MajorUpgradeStrategy = new MajorUpgradeStrategy
{
RemoveExistingProductAfter = Step.InstallInitialize,
UpgradeVersions = VersionRange.OlderThanThis,
PreventDowngradingVersions = VersionRange.NewerThanThis,
NewerProductInstalledErrorMessage = "."
};