首页 > 解决方案 > 构建 wapproj 时 Azure DevOps msbuild 失败

问题描述

我有一个使用带有 Windows 窗体的 .net core 3.1 的项目,以及在同一个解决方案中的一个 Windows 应用程序打包项目。在过去的几个月里,我让这条管道工作了,现在它似乎已经停止工作了。我不确定,但似乎无法从我用来运行管道的托管代理中找到 .target 文件。

我尝试使用 VS Msbuild 步骤和独立的 MSBuild 步骤,还尝试了使用 Nuget 还原步骤的特定 NuGet 版本(5.2.0、5.8.0、5.10.0)。但似乎没有任何帮助。

有谁知道从哪里开始寻找?

错误:

...
CopyFilesToOutputDirectory:
  Copying file from "D:\a\1\s\PrinterAgent\PrinterAgent\obj\Release\netcoreapp3.1\PrinterAgent.dll" to "D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.dll".
  PrinterAgent -> D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.dll
  Copying file from "D:\a\1\s\PrinterAgent\PrinterAgent\obj\Release\netcoreapp3.1\PrinterAgent.pdb" to "D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.pdb".
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent\PrinterAgent.csproj" (default targets).
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): Error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk.
Project "D:\a\1\s\PrinterAgent\PrinterAgent.sln" (1) is building "D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (3) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk. [D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj]
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (default targets) -- FAILED.
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent.sln" (default targets) -- FAILED.

Build FAILED.

"D:\a\1\s\PrinterAgent\PrinterAgent.sln" (default target) (1) ->
"D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (default target) (3) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk. [D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:07.08
##[error]Process 'msbuild.exe' exited with code '1'.

管道定义:使用 windows-2019 代理

pool:
  name: Azure Pipelines
  demands:
  - msbuild
  - azureps

#Your build pipeline references the ‘packageName’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘packageName’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘msixInstallUrl’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘signingCert.password’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘mySecureFile.secureFilePath’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
variables:
  packageVersion: '1.0.0'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 3.1.411'
  inputs:
    version: 3.1.411

- powershell: |
   [xml]$manifest= get-content ".\PrinterAgent\PrinterAgent.Package\Package.appxmanifest"
   $manifest.Package.Identity.Version = "$(packageVersion).$(Build.BuildId)"
   $manifest.Package.Identity.Name = "demo-864d9095-955f-4d3c-adb0-6574a5acb88b"
   $manifest.Package.Properties.DisplayName = "$(packageName)"
   $manifest.Package.Applications.Application.VisualElements.DisplayName = "$(packageName)"
   $manifest.save(".\PrinterAgent\PrinterAgent.Package\Package.appxmanifest")
  displayName: 'PowerShell Script'

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

- task: DownloadSecureFile@1
  displayName: 'Download secure file'
  inputs:
    secureFile: <fileId>

#Fails here
- task: MSBuild@1
  displayName: 'Build solution **/*.sln'
  inputs:
    msbuildVersion: 16.0
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    msbuildArguments: '/p:AppInstallerUri=$(msixInstallUrl) /p:AppxPackageDir="$(Build.ArtifactStagingDirectory)" /p:UapAppxPackageBuildMode=SideLoadOnly /p:GenerateAppInstallerFile=true /p:PackageCertificatePassword="$(signingCert.password)" /p:PackageCertificateKeyFile="$(mySecureFile.secureFilePath)" /p:AppInstallerCheckForUpdateFrequency=OnApplicationRun /p:AppInstallerUpdateFrequency=1 /p:AppInstallerShowPrompt=true'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

- task: AzureCLI@2
  displayName: 'Azure CLI CleanUp blob'
  inputs:
    azureSubscription: <azureSubscription>
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: 'az storage blob delete-batch --account-name <storage> --source ''$web'''

- task: AzureFileCopy@4
  displayName: 'AzureBlob File Copy'
  inputs:
    SourcePath: '$(build.artifactstagingdirectory)/*'
    azureSubscription: <azureSubscription>
    Destination: AzureBlob
    storage: <storageName>
    ContainerName: '$web'

标签: c#.net-coreazure-devopsmsbuild

解决方案


我终于自己修好了。

您需要最新的 .NET SDK 来摆脱MSB4019

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 3.1.x'
  inputs:
    version: 3.1.x

这将引入另一个问题(NETSDK1004见我的评论),可以通过显式恢复打包项目来解决,但这需要 msbuild,尝试类似:

- task: MSBuild@1
  inputs:
    solution: PrinterAgent.Package\PrinterAgent.Package.wapproj
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    msbuildArguments: '/t:restore'

您也可以尝试msbuildArguments通过添加来修改现有的:/t:restore;build


推荐阅读