Explicitly assign component Id in WXS through C# script
abskulkarni opened this issue · 7 comments
Hi @oleg-shilo
I am building WXS through script and build WXS using wix.exe to get final MSI.
However, My components get automatically assigned a very long Id due to long names of components involved. Unfortunately, I cannot reduce component names.
So is there facility to control or explicitly assign component ID?
Hallo, i dont know if this helps. There is example of customID. In Folder Custom_ID
Compiler.AutoGeneration.CustomIdAlgorithm = project.HashedTargetPathIdAlgorithm;
// You need to adjust IsWxsGenerationThreadSafe only if you do concurrent MSI builds
// Compiler.AutoGeneration.IsWxsGenerationThreadSafe = true;
// if you want to modify the string template for HashedTargetPathIdAlgorithm you can do it
// via `AutoGeneration` property.
Compiler.AutoGeneration.HashedTargetPathIdAlgorithm_FileIdMask = "File.{0}.{1}";
Compiler.AutoGeneration.HashedTargetPathIdAlgorithm_FileIdMask = "File_{file_name}_{dir_hash}";
try it, if this helps.
Doesn't help. My component names are exceeding 72 characters. So my custom logic cannot have file name, dir hash etc.
What logic I want is, just take associated feature name and post fix with auto incremented counter. E.g. if feature name is MainFeature then its component ids will be "Component.MainFeature.1", "Component.MainFeature.2" & so on..
Hi @oleg-shilo
I am not adding individual file in a feature directory. As I showed earlier, I am using Files objects with various file extensions as shown below. So in directory, I want to copy all exe, dll, config & xml files from source path.
How can I set custom component id for each these files?
You can always specify some extra steps when processing the file:
new Files(@"..\Release Folder\test\*.exe", x => x.PathGetFileName() != "app-I-do-not-like.exe")
{
OnProcess = file =>
{
file.ComponentId = "whatever",
file.OverwriteOnInstall = true;
}
},
Though, do not forget, that you do not have to rely on WixSharp algorithms only. You have the all power of .NET/C#.
var destDir = project.Dirs.FirstOrDefault();
foreach (var filePath in System.IO.Directory.GetFiles(@"..\Release Folder\test", "*.dll"))
destDir.AddFile(new File(filePath)
{
ComponentId = "whatever"+Guid.NewGuid().ToString("N"),
});
Owner
Thanks @oleg-shilo . That should resolve my problem.
Don't forget that you need to use your specific criteria to find the directory you want to add:
var destDir = project.Dirs.FirstOrDefault(x=>x....your condition here);