oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.12k stars 175 forks source link

Explicitly assign component Id in WXS through C# script #1547

Closed abskulkarni closed 5 months ago

abskulkarni commented 5 months ago

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?

Torchok19081986 commented 5 months ago

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.

abskulkarni commented 5 months ago

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..

oleg-shilo commented 5 months ago

You can assign the comp Id directly from code if you have to:

image

abskulkarni commented 5 months ago

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?

image

oleg-shilo commented 5 months ago

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"),
    });
abskulkarni commented 5 months ago

Owner

Thanks @oleg-shilo . That should resolve my problem.

oleg-shilo commented 5 months ago

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);