You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows Sandbox中安装启用.NET Framework 3.5

在Windows Sandbox中安装.NET Framework 3.5和4.8的解决方案

一、修复.NET Framework 3.5安装的Error 87问题

Error 87通常由命令参数错误、源路径无效或映射文件夹配置不当导致,按以下步骤排查:

  1. 确认映射文件夹配置
    确保你的.wsb文件已正确将主机上存放sxs文件夹的目录映射到Sandbox,示例配置:

    <Configuration>
      <MappedFolder>
        <HostFolder>C:\本地主机的WindowsSandboxScripts路径</HostFolder>
        <SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts</SandboxFolder>
        <ReadOnly>false</ReadOnly>
      </MappedFolder>
      <LogonCommand>
        <Command>powershell -ExecutionPolicy Bypass -File "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\Install-Dependencies.ps1"</Command>
      </LogonCommand>
    </Configuration>
    

    注意:HostFolder需填写主机上的实际路径,Sandbox内路径要与脚本中使用的完全一致。

  2. 修正DISM命令
    确保FeatureName拼写正确(标准为NetFx3),路径用引号包裹避免解析错误:

    DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /Source:"C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\sources\sxs" /LimitAccess
    
  3. 验证源文件有效性
    从与Sandbox同版本的Windows安装镜像中提取sources\sxs文件夹,放到映射目录下。不同版本的镜像文件会导致安装失败。

  4. 添加路径检查与延迟
    Sandbox启动时映射文件夹可能存在加载延迟,可在脚本中先验证路径再执行命令:

    $sourcePath = "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\sources\sxs"
    if (-not (Test-Path $sourcePath)) {
        Start-Sleep -Seconds 5
        if (-not (Test-Path $sourcePath)) {
            Write-Error "源路径不存在,请检查映射配置"
            exit 1
        }
    }
    DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /Source:"$sourcePath" /LimitAccess
    

二、安装.NET Framework 4.8

Windows Sandbox镜像与主机系统版本一致,Windows 10 1903及以上、Windows 11默认已预装.NET Framework 4.8,无需额外安装。若环境缺少该组件,可通过离线包部署:

  1. 下载.NET Framework 4.8离线安装包到主机的映射目录。
  2. 在脚本中添加静默安装命令:
    $installerPath = "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\ndp48-x86-x64-allos-enu.exe"
    Start-Process -FilePath $installerPath -ArgumentList "/quiet /norestart" -Wait
    
    /quiet实现静默安装,/norestart避免自动重启Sandbox。

三、完整PowerShell脚本示例

# 检查并提升至管理员权限
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Start-Process powershell.exe "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
    exit
}

# 安装.NET Framework 3.5
$net35Source = "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\sources\sxs"
if (Test-Path $net35Source) {
    Write-Host "开始安装.NET Framework 3.5..."
    DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /Source:"$net35Source" /LimitAccess
    if ($LASTEXITCODE -eq 0) {
        Write-Host ".NET Framework 3.5安装成功"
    } else {
        Write-Error ".NET Framework 3.5安装失败,错误代码:$LASTEXITCODE"
    }
} else {
    Write-Error "未找到.NET Framework 3.5的源文件路径"
}

# 安装.NET Framework 4.8(按需执行)
$net48Installer = "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\ndp48-x86-x64-allos-enu.exe"
if (Test-Path $net48Installer) {
    Write-Host "开始安装.NET Framework 4.8..."
    Start-Process -FilePath $net48Installer -ArgumentList "/quiet /norestart" -Wait
    if ($LASTEXITCODE -eq 0) {
        Write-Host ".NET Framework 4.8安装成功"
    } else {
        Write-Error ".NET Framework 4.8安装失败,错误代码:$LASTEXITCODE"
    }
} else {
    Write-Host ".NET Framework 4.8安装包未找到,跳过安装(Sandbox可能已预装)"
}

# 安装目标应用
Write-Host "开始安装目标应用..."
# 替换为你的应用安装命令
Start-Process -FilePath "C:\Users\WDAGUtilityAccount\Desktop\WindowsSandboxScripts\YourAppSetup.exe" -ArgumentList "/silent" -Wait

内容的提问来源于stack exchange,提问作者reebo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 17:22:45