前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WPF 打包为 UWP 应用构建失败 MSB3270 不匹配 AMD64 架构

WPF 打包为 UWP 应用构建失败 MSB3270 不匹配 AMD64 架构

作者头像
林德熙
发布2020-03-23 16:43:02
2.2K0
发布2020-03-23 16:43:02
举报
文章被收录于专栏:林德熙的博客

在使用 dotnet core 3.1 的 WPF 打包为 UWP 应用的时候,如果没有设置 PublishProfiles 那么将会在构建 x64 提示所生成项目的处理器架构“AMD64”与引用的处理器架构“x86”不匹配

在我使用下面命令打包的时候,如果我将 Platform 设置为 x86 那么什么问题都没有,如果我设置为 x64 就会发现构建失败,请看 https://github.com/dotnet-campus/TranslationTool/runs/504702520?check_suite_focus=true

代码语言:javascript
复制
msbuild TranslationTool.sln /p:Platform=x64 /p:Configuration=Debug /p:UapAppxPackageBuildMode=StoreOnly /p:AppxBundle=Never /p:PackageCertificateKeyFile=TranslationTool.Package_TemporaryKey.pfx /p:PackageCertificatePassword="123"

可以看到的英文提示如下

代码语言:javascript
复制
(ResolveAssemblyReferences target) ->   
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): error MSB3270: There was a mismatch between the processor architecture of the project being built "AMD64" and the processor architecture of the reference "D:\a\TranslationTool\TranslationTool\Code\TranslationTool.WPF\bin\x86\Debug\netcoreapp3.1\win-x86\TranslationTool.WPF.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [D:\a\TranslationTool\TranslationTool\Code\TranslationTool.Package\TranslationTool.Package.wapproj]

中文提示如下

代码语言:javascript
复制
(ResolveAssemblyReferences 目标) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.ta
rgets(2106,5): error MSB3270: 所生成项目的处理器架构“AMD64”与引用“D:\lindexi\TranslationTool\Code\TranslationTool.WPF\bin
\x86\Debug\netcoreapp3.1\win-x86\TranslationTool.WPF.dll”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。请 考虑通过配置管理器更改您的项目的目标处理器架构,以使您的项目
与引用间的处理器架构保持一致,或者为引用关联一个与您的项目的目标处理器架构相符的处理器架构。

解决方法是添加 PublishProfiles 文件,请看 dotnet-campus/TranslationTool@1650f7a

原因是在使用 .NET Core 3.1 的桌面应用需要修改使用独立发布,也需要指定不同的文件夹

除了在 WPF 项目添加 PublishProfiles 文件,还需要在打包项目添加代码

代码语言:javascript
复制
    <ProjectReference Include="..\lindexi\林德熙博客.csproj">
      <SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
      <TrustLevel>Full</TrustLevel>
      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Release|x86'">Properties\PublishProfiles\SelfContainedWin86.pubxml</PublishProfile>
      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Properties\PublishProfiles\SelfContainedWin64.pubxml</PublishProfile>
      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">Properties\PublishProfiles\SelfContainedWin86Debug.pubxml</PublishProfile>
      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Properties\PublishProfiles\SelfContainedWin64Debug.pubxml</PublishProfile>
    </ProjectReference>

如果使用 msbuild 命令行打包桌面应用为 UWP 应用请看

使用 msbuild 命令行编译 UWP 程序

如何使用 Github 的自动构建请看

Continuous integration and deployment for desktop apps with GitHub Actions

microsoft/github-actions-for-desktop-apps: This repo contains a sample WPF application to demonstrate how to create CI/CD pipelines using GitHub Actions.

如何在 VS 打包请看

UWP 打包 win32 应用 添加防火墙例外

本文链接的是 Github Action 是在 Github 上自动构建的服务,可以用来持续集成,可以用来做 NuGet 包

dotnet 部署 github 的 Action 进行持续集成


本文会经常更新,请阅读原文: https://blog.lindexi.com/post/WPF-%E6%89%93%E5%8C%85%E4%B8%BA-UWP-%E5%BA%94%E7%94%A8%E6%9E%84%E5%BB%BA%E5%A4%B1%E8%B4%A5-MSB3270-%E4%B8%8D%E5%8C%B9%E9%85%8D-AMD64-%E6%9E%B6%E6%9E%84.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者前往 CSDN 关注我的主页

知识共享许可协议
知识共享许可协议

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
持续集成
CODING 持续集成(CODING Continuous Integration,CODING-CI)全面兼容 Jenkins 的持续集成服务,支持 Java、Python、NodeJS 等所有主流语言,并且支持 Docker 镜像的构建。图形化编排,高配集群多 Job 并行构建全面提速您的构建任务。支持主流的 Git 代码仓库,包括 CODING 代码托管、GitHub、GitLab 等。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档