在 github/devops 中构建包含架构依赖图的 vs2022 项目时,构建失败 MSB4226

问题描述 投票:0回答:1

我有一个项目在 github 和 devops 中进行构建。我最近添加了一个架构依赖关系图https://azuredevopslabs.com/labs/devopsserver/livedependencyvalidation/

这在本地构建得很好,并且正确地强制执行依赖关系。

但是,我在 devops 和 github 中构建都失败了。

有趣的是,即使出现错误,如果存在依赖错误,它们似乎也会被正确识别并发出警告。

但是在没有依赖错误的情况下,无论如何构建都会出错。

devops 和 github 都给出相同的错误(见底部)

我在解决方案/项目中有 Microsoft.DependencyValidation.Analyzers nuget。

我在不同的地方看到过其他几篇帖子,但都存在相同的潜在问题,但是是在 VS 的早期版本中。

在链接中,@duncanp 的答案说 ModelingProject.targets 是一种遗留方法,如果您不使用 2015,则可以将其删除。但是引用的行现在不在我的项目/解决方案文件中,所以我无法按照建议删除它们。由于目标最初并不在我的解决方案中,因此我不确定是什么导致了此错误的发生(也许它们是隐式包含的?)

构建服务器上的 Visual Studio 2017 依赖项验证项目

DependencyValidation\DependencyValidation.modelproj(66,11):错误 MSB4226:导入的项目“C:\Program Files\Microsoft Visual Studio�2\Enterprise\MSBuild\Microsoft\VisualStudio 17.0\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject。未找到目标”。另外,尝试在 $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio 17.0" 的后备搜索路径中查找 "ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets" 。这些搜索路径在“C:\Program Files\Microsoft Visual Studio�2\Enterprise\MSBuild\Current\Bin\msbuild.exe.Config”中定义。确认声明中的路径正确,并且该文件存在于磁盘上的搜索路径之一中。

devops 管道(根据相关构建步骤进行调整 ):

parameters:
- name: solution
  default: '**/*.sln'
- name: buildPlatform
  default: 'Any CPU'
- name: buildConfiguration
  default: 'Release'

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
  branches:
    include: 
      - master
#  paths:
#    include: 
#      - 'WIGOV.Applications.Dashboard/**'

pr: none

pool:
  vmImage: 'windows-latest'

steps:
- task: VSBuild@1
  inputs:
    solution: '${{ parameters.solution }}'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
    platform: '${{ parameters.buildPlatform }}'
    configuration: '${{ parameters.buildConfiguration }}'
    msbuildArchitecture: 'x86'

github pipeline(我也尝试过使用 windows-latest 而不是 ubuntu):

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:

  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 8.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --no-restore
    - name: Test
      run: dotnet test --no-build --verbosity normal
    env:
      ARTIFACTORY_USERNAME: "${{ secrets.DSDWI_ARTIFACTORY_USERNAME }}"
      ARTIFACTORY_PASSWORD: "${{ secrets.DSDWI_ARTIFACTORY_PASSWORD }}"
visual-studio github msbuild azure-pipelines devops
1个回答
0
投票

从 YAML 示例中,您正在 Azure Pipeline 中使用 Microsoft 托管代理。

请参阅此文档,了解 Microsoft 托管代理中预安装的 Visual Studio 组件。

Visual Studio 组件:依赖性验证(包含

Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets
)未预安装在所有 Microsoft 托管的代理上。

这就是问题的原因。

要解决此问题,我们需要添加额外的脚本来安装该组件:

Microsoft.VisualStudio.ComponentGroup.ArchitectureTools.Managed
在 Microsoft 托管代理上的 Visual Studio 中。

有关安装 Visual Studio 组件的文档请参阅: 使用命令行参数安装、更新和管理 Visual Studio

在Azure Pipeline中,可以使用以下脚本来实现。

例如:

steps:
- powershell: |
      $source = "https://aka.ms/vs/17/release/vs_enterprise.exe"
      $destination = "$(build.sourcesdirectory)\vs_enterprise.exe"
      $client = new-object System.Net.WebClient 
      $cookie = "oraclelicense=accept-securebackup-cookie"
      $client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie) 
      $client.downloadFile($source, $destination)
  displayName: 'Download vs.exe'

- script: 'vs_enterprise.exe --quiet --wait --norestart --add Microsoft.VisualStudio.ComponentGroup.ArchitectureTools.Managed'
  displayName: 'Install ArchitectureTools'

- script: ls
  workingDirectory: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\ArchitectureTools'
  displayName: 'check install result'

结果:

然后您可以运行 VSbuild 任务来构建您的项目。

但安装过程大约需要6分钟,这会增加Pipeline的运行时间。

您还可以考虑在 Azure Pipeline 中使用自托管代理

这样的话,它会直接使用本地环境来编译你的项目

© www.soinside.com 2019 - 2024. All rights reserved.