Emmanuel
Posts: 17
Joined: Fri Mar 05, 2021 4:01 pm

Automation : How to associate component to a feature?

Hello,

From the code below, I want to associate the component "MyAppFolder" to the feature "MyFeature".
How to do that?

Code: Select all

$advinst = New-Object -ComObject AdvancedInstaller
$project = $advinst.CreateProjectS("architect")

$project.ProductDetails.Name = "MyApp"

$project.ProductDetails.Version = "3.0.0"
$project.ProductDetails.Publisher = "MyCompany"

$project.SaveAs("C:\Users\Administrator\Desktop\MyApp.aip")

$MyFeature = $project.OrganizationComponent.NewFeature("MyFeature")
$MyFeature.Directory = “MyAppDir”
$MyFeature.Parent = "APPDIR"

$MyAppFolder = $project.FilesComponent.AddFolderContentS(“APPDIR\MyAppDir”, “C:\Sources\MyAppFiles")

$project.Save()
Thank you for your help,

Emmanuel
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Automation : How to associate component to a feature?

Hello Emmanuel,

In order to achieve what you want, you can proceed as it follows:

Code: Select all

$advinst = New-Object -ComObject AdvancedInstaller
$project = $advinst.CreateProjectS("architect")

$project.ProductDetails.Name = "MyApp"

$project.ProductDetails.Version = "3.0.0"
$project.ProductDetails.Publisher = "MyCompany"

$project.SaveAs("C:\Users\Administrator\Desktop\MyApp.aip")

$MyFeature = $project.OrganizationComponent.NewFeature("MyFeature")
$MyFeature.Directory = “MyAppDir”
$MyFeature.Parent = "APPDIR"

$MyAppFolder = $project.FilesComponent.AddFolderContentS(“APPDIR\MyAppDir”, “C:\Sources\MyAppFiles")

$folder = $project.FoldersComponent.FindFolderByPath("APPDIR\MyAppDir")
foreach ($file in $folder.Files)
{
   $project.OrganizationComponent.MoveComponentToFeature($file.Component, $MyFeature)
}

$project.Save()
Here would be the code that needs to be added to yours + some comments:

Code: Select all

# find the folder
$folder = $project.FoldersComponent.FindFolderByPath("APPDIR\MyAppDir")
# loop through the files
foreach ($file in $folder.Files)
{
    # move the component of each file to the desired feature
   $project.OrganizationComponent.MoveComponentToFeature($file.Component, $MyFeature)
}
Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Automation : How to associate component to a feature?

You are always welcome, Emmanuel!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”