Why is the project file not found even though I am using an MSBuild task? - msbuild

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!
I've 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, didn't work.
I tried Windows 2019 hosted agent, didn't 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.
Here are some screenshots that show my pipeline tasks:
I also thought maybe x64 architecture would have something to do with it, but that didn't resolve the issue.
I've stumbled on some other interesting posts like this one, but I'm not sure what adding the project to source control 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}"

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:

Related

Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.0.0.0

I am using VS2017, MSBuild version 15.0. I have been installing taichi(https://github.com/yuanming-hu/taichi) .I have been facing lots of errors and trying to solve each step by step and now I am stuck with the following error. I have MSbuid 15.0 but it is looking for version 4.0 .
Build FAILED.
"C:\Users\5000\Documents\spgrid_topo_opt-master\taichi-master\build\taichi.sln" (default target) (1) ->
"C:\Users\5000\Documents\spgrid_topo_opt-master\taichi-master\build\ZERO_CHECK.vcxproj" (default target) (2) ->
(SetTelemetryEnvironmentVariables target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.Cpp.DesignTi
me.targets(491,5): error MSB4062: The "SetEnv" task could not be loaded from the assembly C:\Program Files (x86)
\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets\Microsoft.Build.CppTasks.Common.dll. Could not
load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f
7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask>
declaration is correct, that the assembly and all its dependencies are available, and that the task contains a p
ublic class that implements Microsoft.Build.Framework.ITask. [C:\Users\5000\Documents\spgrid_topo_opt-master\tai
chi-master\build\ZERO_CHECK.vcxproj]
0 Warning(s)
1 Error(s)
1.Please open Developer Command Prompt for VS2017(come with build tools) and type the build command like: msbuild ZERO_CHECK.vcxproj
2.Check if it makes any difference,if same issue persists open vs installer and update the build tools to latest version. Then build the C++ project to check if it helps
I configured the similar environment like yours. And use the SetEnv task in .vcxproj file. But all works well when building the project.
So if all above can't work to resolve the issue: There is possibility that you call msbuild programmatically in code. If so, maybe you can get some help from this issue:
Try binding redirection, thanks to Nicolas.
Also, you can check this thread.
Any update feel free to contact me:)
Edit your PATH environment variable to ensure the first path to a directory containing msbuild.exe is the one included with Visual Studio 2017. This may be one of the following paths, depending on the edition you have and whether you installed it to the default location.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\

How to create Azure Cloud Service package from MsBuild in azure pipeline

I have some cloud service projects , which i am trying to get it into CI/CD. When i right click on the project from Visual Studio and click Package it does what i want. I can see the ServiceConfiguration.cscfg and ServiceDefinition.csdef in the bin\Release folder after the package command is completed.
How can i achieve the same from an MSBuild command line ? I have tried
msbuild.exe
/p:DeployTarget=Package
/p:DeployOnBuild=true
/p:AutomatedBuild=True
/p:configuration=release
/p:outdir="D:\Pub"
/p:targetprofile="Cloud"
/target:Publish
/p:SolutionDir=$/src/mysln/ WorkerRole.ccproj
What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ? Please advice
Edit : Also refered the official docs , could'nt find anything
Edit 2 : Looks like i can get the packages generated. Now the problem is doing this in VSTS. The build is failing with " projectfile="*Undefined*Obfuscator\Maps\
Basically the solution path is becoming as undefined
Edit 3 : Here's the error message when i try to build only the CloudServiceProj
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5165,5): Error MSB3073: The command "if "Release" == "Debug" goto :exit
"*Undefined*Obfuscator\Tool\CO" projectfile="*Undefined*Obfuscator\Maps
The undefined is working fine locally , since it has the $(SolutionDir) variable in VS. Not sure how do i handle it here
Update
Here's the msbuild that am using
Update 4
I tried building the solution directly as suggested, but it has some .NET CORE as well as .NET Framework projects and i am getting this error
C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(163,11): Error MSB4006: There is a circular dependency in the target dependency graph involving target "Publish"..
What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ?
For this question, you can try to change the argument /p:outdir="D:\Pub" to /p:PublishDir="D:\Pub". That because the argument outdir is used to stored the output files not the publish files, it contains the build output of the projects (including the reference project). That the reason why there are around 241 dll and the required files in the folder.
As I test, if I change the argument to PublishDir, it works fine:
For the second question, I am not familiar with Azure Cloud Service, as I know about MSBuild/Visual Studio, we should build the "main" project instead of the reference project, so you can try to build the AzureCloudService.ccproj or build the solution file .sln.
Besides, when we build the project/solution, we do not need specify the solution folder, just specify the project file or solution directly:
msbuild.exe "TheRelativePathForYourSolutionInRepos.sln" /t:Publish /p:DeployOnBuild=true /p:AutomatedBuild=True /p:configuration=release /p:TargetProfile=Cloud /p:PublishDir="D:\Pub"
If above not resolve your questions, please share your build error log in your question.
Update:
For the second part, I have a post build event which does some
obfuscation .
If you have use any Macros, like $(SolutionDir) in your build event, but build the project file, you will got that error. Because the project reference information exists in the solution information, we can't access it when we only build one project.
Try to replace all $(SolutionDir) with $(ProjectDir)..\
Update2:
Since you can build the .sln file on your local without any issue, you could also build the .sln file with Azure pipeline. As test, I could build the .sln file in the Azure pipeline:
Besides, if you have replace $(SolutionDir) with $(ProjectDir)..\, how do you still get the error Undefined? Try to double check you build event, or you can share it in the question.
Hope this helps.

Build fail in msbuild source code(https://github.com/Microsoft/msbuild)

I have cloned MSBuild source code from (https://github.com/Microsoft/msbuild) and followed below steps to build the project.
Building MSBuild with Visual Studio 2017
Install Visual Studio 2017.
Clone the source code
Build the code using the cibuild.cmd script
Open src/MSBuild.sln solution and build in Visual Studio 2017
But build is getting failed with following errors when we try to build from VS 2017
The imported project "C:\msbuildgit\msbuild\packages\Nerdbank.GitVersioning\1.5.46\build\dotnet\Nerdbank.GitVersioning.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. Microsoft.Build.CommandLine.UnitTests
The imported project "C:\msbuildgit\msbuild\packages\Nerdbank.GitVersioning\1.5.46\build\dotnet\Nerdbank.GitVersioning.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. Microsoft.Build.Engine.OM.UnitTests
and also following projects are not getting loaded
Microsoft.Build ,Microsoft.Build.Framework,Microsoft.Build.Tasks
Microsoft.Build.Utilities,MSBuildTaskHost
getting following error , when we try to reload above projects
C:\msbuildgit\msbuild\src\Build\Microsoft.Build.csproj : error : The imported project "C:\msbuildgit\msbuild\packages\Nerdbank.GitVersioning\1.5.46\build\dotnet\Nerdbank.GitVersioning.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. C:\msbuildgit\msbuild\src\dir.targets
following options have been tried and both were getting failed
tried restoring nuget packages
tried installing Nerdbank.GitVersioning nuget(https://www.nuget.org/packages/Nerdbank.GitVersioning/)
Please note that cibuild.cmd script has been already executed
Please help us on this.
Issue has been resolve by following below steps ,Jeff Kluge helped on this after raising this issue in GitHub(https://github.com/Microsoft/msbuild/issues/1947)
Open Developer Command Prompt for VS 2017
Run cd /d C:\msbuildgit\msbuild
Run git clean -xfd to clean the enlistment
Run cibuild.cmd --build-only to build the source code

Microsoft.DNX.Props not found

When i use teamcity to build my VS 2015 project it is getting following error
C:\BuildAgent\work\d7ea2313e2af8fcf\src\Test2015\Test2015.xproj(7, 3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
How can i solve this problem.
Teamcity version - 9.1.3

MSBuild ExtensionPack not found

I have installed the MSBuild.ExtensionPack (From CodePlex) on our BuildServer, but when a build triggered by a Build definition I get the message: "error MSB4019: The imported project "C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks" was not found"
I am completely sure that this path is right!
I can run the very same .proj inside in a command-prompt at the server with no problem, it's only when I try to trigger it as a build definition it fails.
(The .proj-file is located at the server, at D-drive if that's should matter.)