Why is the project file not found even though i am using an MSBuild task?

只愿长相守 提交于 2021-01-07 06:31:55

问题


I created an Azure Devops Build pipeline and i am trying to build my ASP.NET MVC and Angular hybrid site project on bitbucket (git).

The project first gets checked out, and nuget restores the necessary packages, however, i cannot get the .NET to build!

Ive stumbled on this post here that basically advises against using the dotnet build task and recommended just using Visual Studio Build or MSBuild tasks instead.

Nether are working for me though!

  • I tried VS2017-win2016 hosted agent, didnt work.
  • I tried Windows 2019 hosted agent, didnt work.

I am getting this error:

Bobby.ProjectA\Bobby.ProjectA.csproj(713,3): Error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.100\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.100\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk. 
Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1 

 Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\Bobby.ProjectA.Tests\Bobby.ProjectA.Tests.csproj,D:\a\1\s\Bobby.ProjectA\Bobby.ProjectA.csproj 
    D:\a\1\s\Bobby.ProjectA\BobbyProjectA\BobbyProjectA.sln.metaproj(0,0): Error MSB3202: The project file "D:\a\1\s\Bobby.ProjectA\BobbyProjectA\Bobby.ProjectA\Bobby.ProjectA.csproj" was not found. 
    D:\a\1\s\Bobby.ProjectA\BobbyProjectA\BobbyProjectA.sln.metaproj(0,0): Error MSB3202: The project file "D:\a\1\s\Bobby.ProjectA\BobbyProjectA\Bobby.ProjectA.Tests\Bobby.ProjectA.Tests.csproj" was not found. 
    Process 'msbuild.exe' exited with code '1'. 

Since Ubuntu is faster, i also tried that, however, as expected Visual Studio Build task fails with that since VS is not installed on the machine. So i tried with MSBuild and that worked fine with Ubuntu, however, still getting same error that the project file was not found...

Project "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA/Bobby.ProjectA.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA.Tests/Bobby.ProjectA.Tests.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
Done Building Project "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" (default targets) -- FAILED.

Build FAILED.

"/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" (default target) (1) ->
(Build target) -> 
  /home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA/Bobby.ProjectA.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
  /home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA.Tests/Bobby.ProjectA.Tests.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]

I pretty much exhausted my searches and not sure how to solve this.

Heres some screenshots that show my pipeline tasks:

I also thought maybe x64 architecture would have something to do with it, but that didnt resolve the issue...

Ive stumbled on some other interesting posts like this one, but im not sure what adding the project to source countrol means in the answer given, considering my csproj files are already hosted in the repo and being checked out before any tasks run...

My project structure and .sln path (Project):

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bobby.ProjectA", "Bobby.ProjectA\Bobby.ProjectA.csproj", "{12345FE4-4CB9-3245-9A45-DB9A4AF1DFEB}"

回答1:


Based on my test, I could reproduce the similar issue when the wrong csproj file path is mapped in the .sln file.

You could check your .sln file -> project field.

For example:

File structure

The .csproj file is under the WebApplication2 folder, so the project relative path is WebApplication2\WebApplication2.csproj.

.sln file

VisualStudioVersion = 16.0.30611.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{497AD76F-222C-4BEB-BDCB-401B0E80B5CE}"
EndProject

Update:

After discussion with Cataster, the import Project issue can be resolved by specifying **/*.csproj in Msbuild task.

For example:



来源:https://stackoverflow.com/questions/65246997/why-is-the-project-file-not-found-even-though-i-am-using-an-msbuild-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!