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

Azure Pipeline中C++项目缺失project.assets.json问题求助

解决Azure Pipeline中C++/CLI项目不生成project.assets.json的问题

问题场景

  • 包含C#和C++/CLI项目的Visual Studio解决方案,已从.NET Framework 4.8迁移至.NET 8
  • Visual Studio 2022本地构建正常,但Azure Pipeline中dotnet restore无法为C++/CLI项目生成project.assets.json,导致依赖它的C#项目构建失败
  • C++/CLI项目本身无NuGet依赖

方案1:为C++/CLI项目添加空PackageReference

dotnet restore仅会为包含NuGet依赖的项目生成project.assets.json,可以添加一个不影响功能的框架引用包触发文件生成:

  1. 打开C++/CLI项目的.vcxproj文件
  2. 在<Project>节点内插入以下配置:
<ItemGroup>
  <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

该包仅提供框架引用,不会增加项目输出体积,仅用于触发dotnet restore生成所需文件。

方案2:改用MSBuild执行Restore流程

dotnet restore对非SDK-style项目(如C++/CLI)支持有限,改用MSBuild的Restore目标可完整处理所有项目的依赖准备:
将原Pipeline中的DotNetCoreCLI@2 restore步骤替换为:

- task: VSBuild@1
  displayName: 'Restore Solution'
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    msbuildArgs: '/t:Restore'

保留后续的VSBuild构建步骤即可,MSBuild的Restore会自动为C++/CLI项目生成project.assets.json。

方案3:拆分Restore任务分别处理

如果需要保留dotnet restore处理C#项目的高效性,可在其后单独触发C++/CLI项目的Restore:

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj' # 仅针对C#项目执行dotnet restore
    feedsToUse: 'select'
    vstsFeed: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    includeNuGetOrg: true

- task: PowerShell@2
  displayName: 'Restore C++/CLI Projects'
  inputs:
    targetType: 'inline'
    script: |
      msbuild "**\*.vcxproj" /t:Restore /p:Platform=$(buildPlatform) /p:Configuration=$(buildConfiguration)

此方式兼顾C#项目的高效Restore,同时确保C++/CLI项目生成所需文件。


验证提示

先在本地执行对应命令(如msbuild /t:Restore),确认C++/CLI项目的obj目录生成project.assets.json后,再推送Pipeline测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 03:05:16