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

如何构建引用.NET 6标准项目的.NET 7版.NET MAUI应用?

问题:.NET 7 MAUI项目引用同解决方案的.NET 6项目时报错NETSDK1005

报错信息:

error NETSDK1005: Assets file 'XXX\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.

.NET 6类库项目文件内容

<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
  <GenerateDocumentationFile>True</GenerateDocumentationFile>
  <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
  <AnalysisLevel>6.0-all</AnalysisLevel>
</PropertyGroup>

.NET 7 MAUI项目文件内容

<PropertyGroup>
  <TargetFrameworks>net7.0-windows10.0.19041.0</TargetFrameworks>
  <OutputType>Exe</OutputType>
  <UseMaui>true</UseMaui>
  <SingleProject>true</SingleProject>

  <!-- Assembly info -->
  <Title> project title </Title>
  <Company>xyz  Technologies</Company>
  <Product>xyz product </Product>
  <Copyright>Copyright xyz</Copyright>

  <!-- MAUI specific assembly info -->
  <ApplicationTitle> app title </ApplicationTitle>
  <ApplicationId>com.companyname.project</ApplicationId>
  <ApplicationIdGuid>de55addd-a0f9-4c7f-a6d1-81e9937bdab5</ApplicationIdGuid>
  <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  <ApplicationVersion>1</ApplicationVersion>
  <WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>
</PropertyGroup>

解决方案

  • 清理并重新还原项目:删除两个项目的obj和bin文件夹,执行命令 dotnet clean 和 dotnet restore,确保依赖还原完整。
  • 修改.NET 6类库项目文件,添加多目标框架支持,让类库适配MAUI的.NET 7环境:
    将类库中的<TargetFramework>net6.0</TargetFramework>替换为:
    <TargetFrameworks>net6.0;net7.0</TargetFrameworks>
    
    同时可将<AnalysisLevel>6.0-all</AnalysisLevel>改为<AnalysisLevel>latest-all</AnalysisLevel>,适配最新代码分析规则。
  • 确认本地已安装.NET 6和.NET 7 SDK,缺失则前往微软官网下载安装。
  • 检查MAUI项目对类库的引用是否正确,确保引用的是解决方案内的项目而非外部包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 05:37:24