使用 DSC cChocoPackageInstaller 通过 Chocolatey 安装 DotNet 4.6.1 失败

Failure Installing DotNet 4.6.1 via Chocolatey using DSC cChocoPackageInstaller

我正在尝试通过 ARM 模板和 DSC 在 Azure 中设置服务器 Windows 2012 R2。 DSC 脚本 运行s cChocoPackageInstaller 以安装 dotnet4.6.1(在 运行ning cChocoInstaller 之后)。它看起来像这样:

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

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

DotNet 安装程序已下载,但最终在 运行 时失败。日志看起来像这样(我在这里只摘录了错误)。

2016-06-17 13:05:52,001 [DEBUG] - Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\chocolatey\dotnet-461.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.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.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.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'

所以有几件事:

如有任何想法,我们将不胜感激。谢谢!

抱歉耽搁了。所以你需要有一个自动化帐户。我已经修改了我的模板部署脚本以创建自动化帐户,然后使用 Get-AzureRmAutomationRegistrationInfo cmdlet,我得到了主键和端点,如下所示:

$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

然后在模板本身中,您也有一个自动化帐户(来自参数的名称),以及作为其子资源的配置和编译。

有关模板的自动化帐户部分和配置,请参阅 here。 (我最近在做同样的事情,但有问题,但它最终起作用了。)如您所见,配置是一个脚本,用于下载 .net 安装程序并进行安装。仅供参考,这需要重新启动,因此如果您在部署期间在虚拟机上进行任何其他操作,您可能会遇到冲突。

正如我所说,如果需要,您也可以使用自定义脚本扩展来完成。 Msft 在服务分析器站点上有一个脚本可以执行此操作:

{
    "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"
}

并不是说这是最好的答案,但它可以通过 Chocolatey(直接从 CustomScript ARM 扩展启动)或通过 DSC(使用拉服务器和 .Net 4.6.1 的自定义 DSC 模块)来工作要么从 ARM 模板启动。下面是我的 chocolateyInstall.ps1。我基本上是手动进行安装,而不是依赖巧克力安装功能。这来自 the following SO question,它在 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"
}