actions / runner-images

GitHub Actions runner images
MIT License
10.04k stars 3.03k forks source link

Azure Devops Pipeline throwing Error MSB4019 on Windows Server 2019 versions above 20210516.0 #3614

Closed mesakomarevich closed 3 years ago

mesakomarevich commented 3 years ago

Description
Our Azure Devops Pipeline started failing builds with the Visual Studio Build, MSBuild, and MSIX build and package tasks when attempting to build our .msixbundle installer project with the following error:

`

[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.410\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.410\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk.

`

The last change to our pipeline was several months ago, and we narrowed the issue down to a change in the virtual environment by running the unmodified pipeline on the last successful build (being our master branch), which then failed with the exact same MSB4019 error as above.

Our pipeline originally only used the Visual Studio Build task, but in our effort to debug the issue, we tried using the MSBuild and MSIX build and package tasks, both of which failed with the above MSB4019 error message.

After some investigating I found that the Sdk.NuGet.Targets file existed in the C:\Program Files\dotnet\sdk\5.0.301\Sdks\Microsoft.NET.Sdk\Sdk directory on my development machine, but not in the C:\Program Files\dotnet\sdk\3.1.410\Sdks\Microsoft.NET.Sdk\Sdk directory. As such I changed our Use .NET Core task to install .NET 5.x instead of .NET Core 3.x. Doing this then caused a new error to occur when building the project:

`

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

`

Our dotnet restore task originally only had it's Path to project(s) field set with paths to the .csproj files we were building, so I added the path to the installer project's .wapproj. This resulted in no changes to the Visual Studio Build task behavior, and failed again with the same NETSDK1004 error.

We were finally able to resolve this issue by making the following changes to the Visual Studio Build task:

In summary, the following changes were made to our pipeline to resolve this issue:

  1. Use .NET 5.x instead of .NET Core 3.x
  2. Include our .wapproj project in our dotnet restore task
  3. Adding /t:Restore;Build to our list of MSBuild Arguments
  4. Un-checking the Clean parameter of the Visual Studio Build task

I have not yet had a chance to test which combination of the above four changes was necessary to fix our problem, but will provide updates if I find anything new.

Update: The following configuration fails with NETSDK1004:

\ \ The following configuration passes:

\ \ The following configuration fails with NETSDK1004:

\ \ The following configuration fails with NETSDK1004:

\ Area for Triage:
.NET Core

Question, Bug, or Feature?:
Bug

Virtual environments affected

Image version

All versions above 20210516.0

Expected behavior
The project to build without error as we have confirmed that the changes made in our new PRs was not causing the issue.

Actual behavior
The project fails to build, despite no changes being made to the pipeline, and running on code that previously built without issue.

Repro steps
Unfortunately, this is a private repo, so I cannot publicly share our logs or a public example.

mesakomarevich commented 3 years ago

Given the updated testing that I have done, I believe that some change to either the dotnet restore or MSBuild version included with the Windows Server 2019 virtual environment after version 20210516.0 are causing these build problems for us, either that dotnet restore is not correctly restoring packages, or that MSBuild is not correctly interpreting the packages restored with dotnet restore.

dsame commented 3 years ago

@medyagh can you please extract the project configuration from your project, remove all the source code besides main.cs and dependencies?

nikita-bykov commented 3 years ago

Hello @mesakomarevich. Could you please provide us with a public simple repository containing minimal repro steps to speed up our investigation?

nikita-bykov commented 3 years ago

Hello @mesakomarevich. Do you have any updates on repro steps?

nikita-bykov commented 3 years ago

Hello @mesakomarevich. I'm going to close this issue. If you have any updates or questions feel free to reopen the issue.