Failure Installing DotNet 4.6.1 via Chocolatey using DSC cChocoPackageInstaller

泄露秘密 提交于 2020-01-05 04:06:13

问题


I'm attempting to set up a server Windows 2012 R2 in Azure via ARM templates and DSC. The DSC script runs the cChocoPackageInstaller to install dotnet4.6.1 (after running the cChocoInstaller). It looks like this:

cChocoInstaller Choco
{
    InstallDir = "c:\choco"
}

cChocoPackageInstaller DotNet461 
{            
    Name = "dotnet-461" 
    DependsOn = "[cChocoInstaller]Choco" 
} 

The DotNet installer is downloaded but it ultimately fails when it is run. The log looks like this (I've excerpted just the errors here).

2016-06-17 13:05:52,001 [DEBUG] - Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe', statements: '/q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ' 
2016-06-17 13:05:52,001 [DEBUG] - Elevating Permissions and running ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ]. This may take a while, depending on the statements.
2016-06-17 13:05:52,110 [DEBUG] - Setting RunAs for elevation
2016-06-17 13:05:53,487 [INFO ] - The application cannot find one of its required files, possibly
2016-06-17 13:05:53,487 [INFO ] - 
2016-06-17 13:05:53,487 [INFO ] - because it was unable to create it in the folder. Please make
2016-06-17 13:05:53,487 [INFO ] - 
2016-06-17 13:05:53,487 [INFO ] - sure that the folder in which this application was downloaded is
2016-06-17 13:05:53,487 [INFO ] - 
2016-06-17 13:05:53,487 [INFO ] - accessible and not read-only.
2016-06-17 13:05:53,487 [INFO ] - 
2016-06-17 13:05:53,503 [DEBUG] - Command ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ] exited with '3'.
2016-06-17 13:05:53,518 [ERROR] - ERROR: Running ["C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461\4.6.01055.006\NDP461-KB3102436-x86-x64-AllOS-ENU.exe" /q /norestart /log "C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\net461.log" ] was not successful. Exit code was '3'. See log for possible error messages.
2016-06-17 13:05:53,518 [DEBUG] - Built-in PowerShell host called with ['[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name 'c:\choco\helpers\chocolateyInstaller.psm1'; & 'c:\choco\helpers\chocolateyScriptRunner.ps1' -packageScript 'c:\choco\lib\dotnet-461\tools\chocolateyInstall.ps1' -installArguments '' -packageParameters '''] exited with '3'.
2016-06-17 13:05:53,534 [DEBUG] - Calling command ['"C:\Windows\System32\shutdown.exe" /a']
2016-06-17 13:05:53,549 [DEBUG] - Command ['"C:\Windows\System32\shutdown.exe" /a'] exited with '1116'

So a couple of things:

  • No log file is produced for the DotNet installer...so it doesn't look like it's successfully launching the installer.
  • The installer package is definitely downloaded to the expected location. Not sure why it would be able to download the installer to this directory but then later not access/run it.
  • If I RDP onto the box and run the "choco install dotnet4.6.1" command as a local admin the package installs with no errors.
  • I'm now running choco 0.9.10 but had the same issue with 0.9.9
  • I'm running the newer version of the dotnet4.6.1 installer (unapproved) that runs in /q (quite) mode instead of /passive. I had the same issue in Passive mode.

Any ideas are appreciated. Thanks!


回答1:


Sorry about the delay. So you need to have an automation account. I have modified my template deployment script to create the automation account, then with the Get-AzureRmAutomationRegistrationInfo cmdlet, i get the primary key and endpoint like so:

$RegistrationInfo = Get-AzureRmAutomationRegistrationInfo `
    -ResourceGroupName $ResourceGroupName `
    -AutomationAccountName $AccountName

New-AzureRmResourceGroupDeployment `
    -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
    -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile `
    -TemplateParameterFile $TemplateParametersFile `
    # extra params here
    -RegistrationKey ($RegistrationInfo.PrimaryKey | ConvertTo-SecureString -AsPlainText -Force) `
    -RegistrationUrl $RegistrationInfo.Endpoint `
    -AutomationAccountName $AccountName

Then in the template itself, you have an automation account there as well (name from param), and as child resources of that, a configuration and a compilation.

See here for automation account part of the template and the configuration. (I was doing the same thing v recently, with issues, but it works in the end.) As you can see, the configuration is a script that downloads .net installer and installs. FYI, this requires a reboot, so if you have anything else going on on the vm during deploy, you may get conflicts.

Like I said, you can also do it with a custom script extension if you want. Msft have a script on service profiler site that does it:

{
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.7",
        "autoUpgradeMinorVersion": false,
        "settings": {
            "fileUris": [ "https://serviceprofiler.azurewebsites.net/content/downloads/InstallNetFx46.ps1" ],
            "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File InstallNetFx46.ps1"
        },
        "forceUpdateTag": "RerunExtension"
    },
    "name": "CustomScriptExtensionInstallNet46"
}



回答2:


Not saying this is the best answer possible, but this works both via Chocolatey (launched directly from a CustomScript ARM extension) or via DSC (using a pull server and a custom DSC module for .Net 4.6.1) when either is initiated from an ARM template. Below is from my chocolateyInstall.ps1. I'm basically manually conducting the install instead of relying on the chocolatey install functionality. This came from the following SO question which used this approach for 4.5.2.

Function IsInstalled {
    $ver = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release
    return (!($ver -eq $null) -and ($ver -ge 394254))
}

if (IsInstalled) {
    Write-Host "Microsoft .NET Framework 4.6.1 or later is already installed"
}
else {
    $SourceURI = "https://download.microsoft.com/download/3/5/9/35980F81-60F4-4DE3-88FC-8F962B97253B/NDP461-KB3102438-Web.exe"
    $FileName = $SourceURI.Split('/')[-1]
    $BinPath = Join-Path $env:SystemRoot -ChildPath "Temp\$FileName"

    if (!(Test-Path $BinPath))
    {
        Invoke-Webrequest -Uri $SourceURI -OutFile $BinPath
    }

    write-verbose "Installing .Net 4.6.1 from $BinPath"
    write-verbose "Executing $Binpath /q /norestart"
    Sleep 5
    Start-Process -FilePath $BinPath -ArgumentList "/q /norestart" -Wait -NoNewWindow            
    Sleep 5
    Write-Verbose "DotNet 4.6.1 Install completed"
}


来源:https://stackoverflow.com/questions/37885696/failure-installing-dotnet-4-6-1-via-chocolatey-using-dsc-cchocopackageinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!