Azure Pipeline - 从具有项目依赖项的解决方案构建一个项目

Azure Pipeline - Build one project from solution with project dependencies

我有一个包含几个项目的解决方案。

App.Client.DatabaseApp.Client.Connectors都是App.Client.WebsiteApp.Client.WindowsService的依赖,App.Shared是所有项目的依赖

我想创建 2 个管道:一个用于网站,一个用于 windows 服务。

我遇到的问题是,当我将 解决方案 设置为 App.Client.Website/*.csproj 时,它找不到任何要构建的项目引用 - 这使得对我来说很有意义,但我显然也希望它能构建我的项目引用。

我尝试通过为每个打包 nuget 包的依赖项目创建管道来解决这个问题,然后我会从我的网站和 window 服务项目的提要中引用该 nuget 包,但这停止了我能够调试代码并即时更改这些项目。

DevOps 是我才刚刚开始接触的东西。我已经到了需要向我的网站应用程序添加内部版本号并希望停止手动递增补丁程序号的地步。我正在使用 YAML 而不是经典管道构建器。

感谢任何帮助。

YAML 这是我正在使用的 YAML。它只是针对我的网站项目的解决方案的基本 YAML。

# 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:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.Client.Website/*.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: 'config'
    nugetConfigPath: 'Pipelines/nuget.config'
    externalFeedCredentials: 'External Feed'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

repo 文件夹结构在 repo 的根目录下有项目文件夹。

我的网站cs项目文件中的项目引用如下:

<ItemGroup>
    <ProjectReference Include="..\App.Client.Database\App.Client.Database.csproj" />
    <ProjectReference Include="..\App.Client.Connectors\App.Client.Connectors.csproj" />
    <ProjectReference Include="..\App.Shared\App.Shared.csproj" />
</ItemGroup>

这是构建任务的错误:

##[error]C:\Program Files\dotnet\sdk.1.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): Error NETSDK1004: Assets file 'D:\a\s\App.Shared\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

问题与NuGet Restore任务有关,我们可以尝试恢复.sln文件来恢复所有NuGet包,然后构建.csproj文件。它应该有效。