We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

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: 7853
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: 7853
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”