sub DoProductPackaging()

in build/scripts/automation/winbldroutines.pm [1448:1833]


sub DoProductPackaging
{
  print "DEBUG: in DoProductPackaging()\n";

  my $this = shift;
  my $srcpath = $this->SrcPath();
  my $partner = $this->Partner();
  my $partnerstring = $this->GetPartnerString();
  my $configlist = $this->ConfigList();
  my $productlist = $this->ProductList();
  my $datewisedir = $this->DatewiseDir();
  my $MajorVersion = $this->GetMajorVersion();
  my $MinorVersion = $this->GetMinorVersion();
  my $PatchSetVersion = $this->GetPatchSetVersion();
  my $PatchVersion = $this->GetPatchVersion();
  my $branchname = $this->Branch();
  my $partnercode = $this->GetPartnerCode();
  my $bldphase = $this->BuildPhase();
  my $pvt = 1;
  my $date = $this->Date();
  my $month = $this->Month();
  my $year = $this->Year();
  my $buildphase = $this->BuildPhase();
  my $signing = $this->Signing();
  my $buildpath = "${MajorVersion}.${MinorVersion}";

  my ($outputfilename,$targetfilename,$solnfile,$buildproject,$packagingproject,$packagingoutputdir,$logfile);
  
  foreach my $config (reverse sort @{$configlist})
  {
    foreach my $product (@{$productlist})
    {	
		# Skip packaging if the product is UA/CX/PI as we don't need to generate installers for them.
		next if uc($product) eq "UA" or uc($product) eq "CX";
		
		$buildproject = $this->GetBuildProjectName($product);
		$packagingproject = $this->GetPackagingProjectName($product);
		$packagingoutputdir = $this->GetBuildIssDir($product);
		$logfile = "${srcpath}\\${packagingoutputdir}\\PackagingLog_${product}_${config}_${partner}.txt";
		$solnfile = $this->GetSolnFileName($product);
		unlink "$logfile" if -e "$logfile";	
		my $product = uc($product);
		
		# Populate version.iss file when product is CX_TP or UCX.
		if (uc($product) eq "CX_TP" or uc($product) eq "UCX")
		{
			Log_Do("rename $srcpath\\host\\setup\\version.iss version.iss.orig");
			my $productname = uc($product);
			my $timeinsecs = $this->TimeInSecs();
			my $refsecs = $this->GetRefSecs();
			my $smrrefsecs = $this->GetSMRRefSecs();
			my $dlybldnum = int(($timeinsecs - $refsecs)/86400);
			my $smrdlybldnum = int(($timeinsecs - $smrrefsecs)/86400);
			my $bldquality = $this->BuildQuality();
			my $tagstring = "${bldquality}_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_${bldphase}_${dlybldnum}_${month}_${date}_${year}_${partnerstring}";
			open(FH_W_V_ISS,">$srcpath\\host\\setup\\version.iss") or die "Could not open $srcpath\\host\\setup\\version.iss";
			my $version_iss_contents = "#define VERSION \"${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}\"\n";
			$version_iss_contents = $version_iss_contents . "#define PRODUCTVERSION \"${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}\"\n";
			$version_iss_contents = $version_iss_contents . "#define APPVERSION \"${MajorVersion}.${MinorVersion}.${dlybldnum}.${partnercode}\"\n";
			$version_iss_contents = $version_iss_contents . "#define PRODUCTNAME \"${productname}\"\n";
			$version_iss_contents = $version_iss_contents . "#define BUILDTAG \"${tagstring}\"\n";
			$version_iss_contents = $version_iss_contents . "#define BUILDNUMBER \"${dlybldnum}\"\n";
			$version_iss_contents = $version_iss_contents . "#define BUILDPHASE  \"${bldphase}\"\n";
			$version_iss_contents = $version_iss_contents . "#define PARTNERCODE \"${partnercode}\"\n";
			$version_iss_contents = $version_iss_contents . "#define BUILDDATE \"${date}${month}${year}\"\n";
			$version_iss_contents = $version_iss_contents . "#define SMRBUILDNUMBER \"${smrdlybldnum}\"\n";
			$version_iss_contents = $version_iss_contents . "#define COPYRIGHT \"(c) ${year} Microsoft Corp. All rights reserved.\"\n";
			print FH_W_V_ISS $version_iss_contents;
			close(FH_W_V_ISS);
			print "version.iss contents are:\n\n$version_iss_contents\n\n";
	    }

		# Populate manifest.txt and copy Linux agents, push clients, DRA and MARS agents when product is UCX.
		if (uc($product) eq "UCX")
		{		
			# Populate host\setup\manifest.txt
			open(FH_W_V_ISS,">$srcpath\\host\\setup\\manifest.txt") or die "Could not open $srcpath\\host\\setup\\manifest.txt";
			my $manifest_contents = "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_Windows_${bldphase}_${date}${month}${year}_${config}.exe,1,Windows,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_RHEL5-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,RHEL5-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_RHEL6-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,RHEL6-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_RHEL7-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,RHEL7-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_RHEL8-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,RHEL8-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_OL6-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,OL6-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_OL7-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,OL7-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_OL8-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,OL8-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_SLES11-SP3-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,SLES11-SP3-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_SLES11-SP4-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,SLES11-SP4-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_SLES12-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,SLES12-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_SLES15-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,SLES15-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_UBUNTU-14.04-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,UBUNTU-14.04-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_UBUNTU-16.04-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,UBUNTU-16.04-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_UBUNTU-18.04-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,UBUNTU-18.04-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_UBUNTU-20.04-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,UBUNTU-20.04-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_DEBIAN7-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,DEBIAN7-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_DEBIAN8-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,DEBIAN8-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_DEBIAN9-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,DEBIAN9-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			$manifest_contents = $manifest_contents . "Microsoft-ASR_UA_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_DEBIAN10-64_${bldphase}_${date}${month}${year}_${config}.tar.gz,2,DEBIAN10-64,,${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion},Upgrade,no\n";
			
			print FH_W_V_ISS $manifest_contents;
			close(FH_W_V_ISS);
			print "manifest.txt contents are:\n\n$manifest_contents\n\n";
			
			# Copy Linux agents, push clients, DRA and MARS agent from their corresponding staging servers.
			system($PowerShellPath ' -File "Copy_RHEL.ps1"', $branchname, $buildpath, $config );
	    }
		
		# Set modified timestamp of CX_TP Perl modules 48 hours back. 
		if (uc($product) eq "CX_TP")
		{	
			foreach my $dirname ("Win32-0.39", "Win32-OLE-0.1709", "Win32-Process-0.14", "Win32-Service-0.06")
			{			
				my $dirpath = $srcpath . "\\thirdparty\\server\\" . $dirname;
				ChangeModifiedTime($dirpath);
			}
		}
		
		# Set modified timestamp of UCX Perl modules 48 hours back.
		if (uc($product) eq "UCX")
		{	
			foreach my $dirname ("Win32-UTCFileTime-1.50")
			{			
				my $dirpath = $srcpath . "\\thirdparty\\server\\" . $dirname;
				ChangeModifiedTime($dirpath);
			}
		}
		
		if (uc($product) eq "PSMSI") 
		{
			# Generate PSMSI package
			if (Log_Do("\"$mvss_exe\" ${srcpath}\\$solnfile /project ProcessServerMSI /build \"$config|x64\" /out $logfile") == 0 ) {
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				print "\n\n$config build from $branchname is successful for $product for ProcessServerMSI in $addr\n\n";
			} 
			else 
			{
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				send_mail($failure_alert_ids,'Windows build failure',"$config build from $branchname is failed for $product for ProcessServerMSI in $addr",1);
				die "\n\n$config build from $branchname is failed for $product for ProcessServerMSI in $addr";
			}
		}
		
		if (uc($product) eq "ASRUA") 
		{		
			foreach my $proc ("x86", "x64")
			{
				# Generate both 32-bit and 64-bit MSIs.
				if (Log_Do("\"$mvss_exe\" ${srcpath}\\$solnfile /project UnifiedAgentMSI /build \"$config|$proc\" /out $logfile") == 0 ) {
					Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
					print "\n\n$config build from $branchname is successful for $product for UnifiedAgentMSI in $addr\n\n";				
				} 
				else 
				{
					Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
					send_mail($failure_alert_ids,'Windows build failure',"$config build from $branchname is failed for $product for UnifiedAgentMSI in $addr",1);
					die "\n\n$config build from $branchname is failed for $product for UnifiedAgentMSI in $addr";
				}
			}
			
			# Sign both 32-bit and 64-bit MSIs.
			my ($weekday,$month,$sdate,$hour,$min,$sec,$year) = ( localtime =~ /^(\w{3})\s+(\w{3})\s+(\d{1,2})\s+(\d{1,2}):(\d{2}):(\d{2})\s+(\d{4})$/ );
			$sdate = sprintf("%02d", $sdate);
			my $sdate = "${sdate}_${month}_${year}";
		
			# Copy unmanaged binaries to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Binaries_To_Submission_Path.ps1"' , $config , "ASRUAMSI" , $srcpath, $branchname, $signing);
		
			# Delete signing related files if they exists.	
			my @signfilestoberemoved = ("InputSign.json", "OutputSign.json", "OutputSignVerbose.log");
			foreach (@signfilestoberemoved) {
				Log_Do("if exist I:\\Signing\\$branchname\\$sdate\\ASRUAMSI\\$_ del /F I:\\Signing\\$branchname\\$sdate\\ASRUAMSI\\$_");
			}	
		
			# Variables related to signing.
			my $inputfileslist = "$srcpath\\build\\scripts\\automation\\CodeSignScripts\\Files.json";
			my $sourcerootdir = "\t\t\"SourceRootDirectory\":" . " \"I:\\\\Signing\\\\$branchname\\\\$sdate\\\\ASRUAMSI\\\\Unsigned\\\\$config\",\n";
			my $destrootdir = "\t\t\"DestinationRootDirectory\":" . " \"I:\\\\Signing\\\\$branchname\\\\$sdate\\\\ASRUAMSI\\\\Signed\\\\$config\",\n";
			my $inputtempfile = "$srcpath\\build\\scripts\\automation\\CodeSignScripts\\InputSignTemplate.json";
			my $inputfile = "I:\\Signing\\$branchname\\$sdate\\ASRUAMSI\\InputSign.json";
			my $outputfile = "I:\\Signing\\$branchname\\$sdate\\ASRUAMSI\\OutputSign.json";
			my $verboselogfile = "I:\\Signing\\$branchname\\$sdate\\ASRUAMSI\\OutputSignVerbose.log";
		
			# Prepare files for signing.
			my $filessection = "ASRUA_MSI_SIGN_FILES";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");

			# Submit MSIs for signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
			
			# Copy unmanaged binaries to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Signed_Binaries_To_Build_Path.ps1"' , $config , "ASRUAMSI" , $srcpath, $branchname, $signing);			
			
			# Generate UnifiedAgent package
			if (Log_Do("\"$mvss_exe\" ${srcpath}\\$solnfile /project PackagerUnifiedAgent /build \"$config|Any\ CPU\" /out $logfile") == 0 ) {
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				print "\n\n$config build from $branchname is successful for $product for PackagerUnifiedAgent in $addr\n\n";
			} 
			else 
			{
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				send_mail($failure_alert_ids,'Windows build failure',"$config build from $branchname is failed for $product for PackagerUnifiedAgent in $addr",1);
				die "\n\n$config build from $branchname is failed for $product for PackagerUnifiedAgent in $addr";
			}
		}
		elsif (uc($product) eq "ASRSETUP") 
		{
			my $product = uc($product);              
			# Build UnifiedSetup Packager
			if (Log_Do("\"$mvss_exe\" ${srcpath}\\$solnfile /project Packager /build \"$config|Any\ CPU\" /out $logfile") == 0 ) {
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				print "\n\n$config build from $branchname is successful for $product for packager in $addr\n\n";
			} 
			else 
			{
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				send_mail($failure_alert_ids,'Windows build failure',"$config build from $branchname is failed for $product for packager in $addr",1);
				die "\n\n$config build from $branchname is failed for $product for packager in $addr";
			}   
		}
		elsif (uc($product) eq "PI")
		{
			my $product = uc($product);
			print "\n\nSkipping packaging as product is $product\n\n";
		}
		else
		{
			if (Log_Do("\"$mvss_exe\" ${srcpath}\\$solnfile /project $packagingproject /build \"$config|Win32\" /out $logfile") == 0) {
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				print "\n\n$config packaging for $branchname is successful for $product in $addr\n\n";
			} else {
				Log_Do("if exist $logfile copy /Y $logfile ${datewisedir}\\${config}\\logs");
				send_mail($failure_alert_ids,'Windows build failure',"$config packaging for $branchname is failed for $product in $addr",1);
				die "\n\n$config packaging for $branchname is failed for $product in $addr";
			}
		}

		# Sign installers.
		my ($weekday,$month,$sdate,$hour,$min,$sec,$year) = ( localtime =~ /^(\w{3})\s+(\w{3})\s+(\d{1,2})\s+(\d{1,2}):(\d{2}):(\d{2})\s+(\d{4})$/ );
		$sdate = sprintf("%02d", $sdate);
		my $sdate = "${sdate}_${month}_${year}";	
		
		# Delete signing related files if they exists.	
		my @signfilestoberemoved = ("InputSign.json", "OutputSign.json", "OutputSignVerbose.log");
		foreach (@signfilestoberemoved) {
			Log_Do("if exist I:\\Signing\\$branchname\\$sdate\\${product}_INSTALLER\\$_ del /F I:\\Signing\\$branchname\\$sdate\\${product}_INSTALLER\\$_");
		}	
		
		# Variables specific to signing.
		my $inputfileslist = "$srcpath\\build\\scripts\\automation\\CodeSignScripts\\Files.json";
		my $sourcerootdir = "\t\t\"SourceRootDirectory\":" . " \"I:\\\\Signing\\\\$branchname\\\\$sdate\\\\${product}_INSTALLER\\\\Unsigned\\\\$config\",\n";
		my $destrootdir = "\t\t\"DestinationRootDirectory\":" . " \"I:\\\\Signing\\\\$branchname\\\\$sdate\\\\${product}_INSTALLER\\\\Signed\\\\$config\",\n";
		my $inputtempfile = "$srcpath\\build\\scripts\\automation\\CodeSignScripts\\InputSignTemplate.json";
		my $inputfile = "I:\\Signing\\$branchname\\$sdate\\${product}_INSTALLER\\InputSign.json";
		my $outputfile = "I:\\Signing\\$branchname\\$sdate\\${product}_INSTALLER\\OutputSign.json";
		my $verboselogfile = "I:\\Signing\\$branchname\\$sdate\\${product}_INSTALLER\\OutputSignVerbose.log";
		
		if (uc($product) eq "CX_TP") 
		{
			# Copy installer to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Installers_To_Submission_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
			
			# Prepare files for signing.
			my $filessection = "CXTP_SIGN_INSTALLER";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");
		
			# Submit installer or signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
		
			# Copy installer to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Singed_Installers_To_Build_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
		}
		
		if (uc($product) eq "UCX") 
		{
			# Copy installer to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Installers_To_Submission_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
	
			# Prepare files for signing.
			my $filessection = "UCX_SIGN_INSTALLER";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");
		
			# Submit installer for signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
			
			# Copy installer to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Singed_Installers_To_Build_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);			
		}
	
		if (uc($product) eq "ASRUA") 
		{
			$packagingoutputdir = qw(host\ASRSetup\PackagerUnifiedAgent\bin);	
	
			# Copy installer to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Installers_To_Submission_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
	
			# Prepare files for signing.
			my $filessection = "ASRUA_SIGN_INSTALLER";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");

			# Submit installer for signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
			
			# Copy installer to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Singed_Installers_To_Build_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
		}   

		if (uc($product) eq "PSMSI") 
		{	
			$packagingoutputdir = qw(\server\windows\ProcessServerMSI\x64\bin);
		
			# Copy installer to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Installers_To_Submission_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
	
			# Prepare files for signing.
			my $filessection = "PSMSI_SIGN_FILES";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");

			# Submit installer or signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
			
			# Copy installer to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Singed_Installers_To_Build_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
		}
		
		if (uc($product) eq "ASRSETUP") 
		{
			$packagingoutputdir = qw(host\ASRSetup\Packager\bin);        
			
			# Copy installer to submission path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Unsinged_Installers_To_Submission_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
	
			# Prepare files for signing.
			my $filessection = "ASRSETUP_SIGN_INSTALLER";
			prepare_signing_files ("$inputfileslist", "$filessection", "$inputtempfile", "$inputfile", "$sourcerootdir", "$destrootdir");

			# Submit installer for signing.
			submit_files_for_signing("$product", "$config", "$inputfile", "$outputfile", "$verboselogfile");
					
			# Copy installer to build path.
			system($PowerShellPath ' -File ".\\CodeSignScripts\\Copy_Singed_Installers_To_Build_Path.ps1"' , $config , $product , $srcpath, $branchname, $signing);
		}
		
		if (uc($product) eq "PI")
		{
			my $product = uc($product);
			print "\n\nSkipping exe file packaging as product is $product and build is disabled for this.\n\n";
		}
		else
		{
			$outputfilename = "${srcpath}\\${packagingoutputdir}\\${config}\\" . $this->GetOutputFileName($product);
			die "\n\nCannot find outputfilename - $outputfilename" unless -e $outputfilename;
		}
	
		if (uc($product) eq "UCX")
		{
			$targetfilename = "${datewisedir}\\${config}\\Microsoft-ASR_" . "CX" . "_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_Windows_${buildphase}";
		}
		elsif (uc($product) eq "ASRUA")
		{
			$targetfilename = "${datewisedir}\\${config}\\Microsoft-ASR_UA" . "_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_Windows_${buildphase}";
		}
		else
		{
			$targetfilename = "${datewisedir}\\${config}\\Microsoft-ASR_" . uc($product) . "_${MajorVersion}.${MinorVersion}.${PatchSetVersion}.${PatchVersion}_Windows_${buildphase}";
		}
		$targetfilename = $targetfilename . "_${date}${month}${year}_${config}.exe";	
		
		if (uc($product) eq "ASRSETUP") 
		{
			$targetfilename = "${datewisedir}\\${config}\\" . $this->GetOutputFileName($product);
		}
		elsif (uc($product) eq "PSMSI")
		{
			$targetfilename = "${datewisedir}\\${config}\\" . $this->GetOutputFileName($product);
		}
		
		my $prodversion = "${MajorVersion}.${MinorVersion}";
		if (Log_Do("copy /Y $outputfilename $targetfilename")==0) {
			print "\n\nPackaged $targetfilename successful\n\n";
			system($PowerShellPath ' -File "TRUNK_Builds_Copy.ps1"' , $config , uc($product), $branchname, $buildpath, $prodversion);
		} else {
			send_mail($failure_alert_ids,'Windows build failure',"Packaging failure from $branchname for $product for $config in $addr",1);
			die "\n\nPackaging failure from $branchname for $product for $config";
		}
    }
  }
}