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

Linux流水线构建时Microsoft.DesktopBridge.props项目导入失败求助

解决Linux流水线构建WinForms MSIX包时找不到Microsoft.DesktopBridge.props的问题

问题概述

本地通过Visual Studio可正常构建WinForms应用并生成MSIX包,但提交至Linux CI流水线后构建失败,报错无法找到Microsoft.DesktopBridge.props文件。

报错信息

/runner/_work/WinPackageMSIX/WinPackageMSIX.wapproj(19,3): error MSB4019: 找不到导入的项目"/runner/_work/.dotnet/sdk/6.0.417/Microsoft/DesktopBridge/Microsoft.DesktopBridge.props"。确认Import声明中的表达式"/runner/_work/.dotnet/sdk/6.0.417/Microsoft/DesktopBridge//Microsoft.DesktopBridge.props"是否正确,以及文件是否存在于磁盘上。

涉及的WapProj内容

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
        <VisualStudioVersion>15.0</VisualStudioVersion>
    </PropertyGroup>
    <ItemGroup Label="ProjectConfigurations">
        <ProjectConfiguration Include="Debug|x64">
            <Configuration>Debug</Configuration>
            <Platform>x64</Platform>
        </ProjectConfiguration>
        <ProjectConfiguration Include="Release|x64">
            <Configuration>Release</Configuration>
            <Platform>x64</Platform>
        </ProjectConfiguration>
    </ItemGroup>
    <PropertyGroup>
        <WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
    </PropertyGroup>
    <Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
    <PropertyGroup>
        <ProjectGuid>dcc67232-cf92-4498-92c1-2281dc72320b</ProjectGuid>
        <TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
        <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
        <DefaultLanguage>en-US</DefaultLanguage>
        <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
        <NoWarn>$(NoWarn);NU1702</NoWarn>
        <EntryPointProjectUniqueName>..\..\src\WinForms\WinForms.csproj</EntryPointProjectUniqueName>
        <PackageCertificateKeyFile>1B7886C50F577F6DBA492ED28145D20BE20546</PackageCertificateKeyFile>
        <AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
        <AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
        <AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
        <AppxBundlePlatforms>x64</AppxBundlePlatforms>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
        <AppxBundle>Never</AppxBundle>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
        <AppxBundle>Never</AppxBundle>
    </PropertyGroup>
    <ItemGroup>
        <AppxManifest Include="Package.appxmanifest">
            <SubType>Designer</SubType>
        </AppxManifest>
    </ItemGroup>
    <ItemGroup>
        <Content Include="Images\SplashScreen.scale-200.png" />
        <Content Include="Images\LockScreenLogo.scale-200.png" />
        <Content Include="Images\Square150x150Logo.scale-200.png" />
        <Content Include="Images\Square44x44Logo.scale-200.png" />
        <Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
        <Content Include="Images\StoreLogo.png" />
        <Content Include="Images\Wide310x150Logo.scale-200.png" />
    </ItemGroup>
    <Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" PrivateAssets="all" />
    </ItemGroup>
    <ItemGroup>
        <ProjectReference Include="..\..\src\WinForms\WinForms.csproj" />
    </ItemGroup>
</Project>

原因分析

Microsoft.DesktopBridge.props及相关MSBuild目标是Windows平台专属组件,Linux版本的.NET SDK默认不包含这些文件。MSIX是Windows独有的应用打包格式,其构建流程依赖Windows特有的SDK工具和组件,无法在Linux环境中完成完整的打包流程。

解决方案

1. 切换至Windows构建代理

这是最直接且可靠的方案:将CI流水线的构建环境改为Windows虚拟机或容器。例如:

  • GitHub Actions中使用windows-latest运行器
  • GitLab Runner配置Windows executor
  • Azure DevOps选择Windows虚拟机作为构建代理

Windows环境会自动包含MSIX打包所需的所有SDK组件,和本地Visual Studio构建环境一致,可直接完成构建。

2. 尝试通过NuGet包调整路径(仅解决文件找不到问题,后续打包仍会失败)

虽然无法在Linux上完成MSIX打包,但可以修改WapProj的WapProjPath属性,指向Microsoft.Windows.SDK.BuildTools NuGet包内的对应路径,暂时解决文件找不到的错误:

<PropertyGroup>
    <WapProjPath Condition="'$(WapProjPath)'==''">$(NuGetPackageRoot)microsoft.windows.sdk.buildtools\10.0.22621.1\build\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>

注意:此操作仅能解决当前文件找不到的报错,后续的MSIX打包、签名等步骤依然会因缺少Windows工具而失败,因此仅作为临时排查手段,最终仍需使用Windows构建环境。

3. 预构建MSIX后再进入Linux流水线

如果必须保留Linux流水线,可以在独立的Windows构建环节(如本地预构建、专门的Windows CI任务)中生成MSIX包,然后将包文件传递到Linux流水线中进行后续的分发、部署等操作。

内容的提问来源于stack exchange,提问作者to-mars

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 21:07:33