.NET 8在Azure DevOps构建时出现NETSDK1112运行时包未下载错误
解决.NET 8 MSIX WPF应用在Azure DevOps构建时的NETSDK1112错误
核心原因
Azure DevOps中VSBuild@1任务默认依赖代理上Visual Studio自带的MSBuild环境,可能无法正确识别通过UseDotNet@2安装的.NET 8 SDK及对应运行时包,导致还原阶段无法找到Microsoft.NETCore.App.Runtime.win-x64和Microsoft.WindowsDesktop.App.Runtime.win-x64。
解决方案1:改用DotNetCoreCLI@2任务构建(推荐)
DotNetCoreCLI任务直接与UseDotNet@2安装的.NET SDK集成,能避免VSBuild的环境依赖问题。将Azure DevOps pipeline中的VSBuild任务替换为以下步骤:
- 还原依赖
- task: DotNetCoreCLI@2 displayName: '还原.NET 8依赖' inputs: command: 'restore' projects: '**/*.csproj' feedsToUse: 'select'
- 构建并发布MSIX包
- task: DotNetCoreCLI@2 displayName: '构建并发布MSIX' inputs: command: 'publish' projects: '**/*.csproj' arguments: '-c Release -r win-x64 /p:GenerateAppxPackageOnBuild=true' publishWebProjects: false
解决方案2:调整VSBuild@1任务参数(保留VSBuild场景)
如果必须使用VSBuild,需强制任务使用通过UseDotNet@2安装的.NET 8 SDK,修改VSBuild任务的msbuildArgs:
- task: VSBuild@1 displayName: '构建MSIX项目' inputs: solution: '**/*.csproj' platform: 'x64' configuration: 'Release' msbuildArgs: > /p:Restore=true /p:RuntimeIdentifier=win-x64 /p:TargetFramework=net8.0-windows10.0.19041.0 /p:DotNetRoot=$(Agent.ToolsDirectory)/dotnet
项目文件补充配置(可选,增强稳定性)
在WPF项目的.csproj中明确指定运行时版本,避免版本歧义:
<PropertyGroup> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- 明确指定.NET 8运行时版本 --> <RuntimeFrameworkVersion>8.0.0</RuntimeFrameworkVersion> <UseWPF>true</UseWPF> <GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild> </PropertyGroup>
前置验证步骤
确保UseDotNet@2任务正确安装了完整的.NET 8 SDK(而非仅运行时):
- task: UseDotNet@2 displayName: '安装.NET 8 SDK' inputs: packageType: 'sdk' version: '8.x' includePreviewVersions: false
内容的提问来源于stack exchange,提问作者Rye bread
相关产品推荐
相关产品推荐

