I am trying to build a solution on my jenkins pipeline using MSBuild. Here are the stages :
Here is the script of my pipeline for the part related to nuget packages :
environment {
nuget = "C:/nuget.exe"
}
stages {
stage('Restore Nuget Packages') {
steps {
script {
bat '%nuget% restore "./trunk/BALANCE/TakK_BAL.sln\"'
}
}
}
stage('Build') {
steps {
script {
bat "\"${tool 'MSBuild'}\\MSBuild.exe\" \"./trunk/BALANCE/TakK_BAL.sln\" /p:Configuration=Debug /p:Platform=\"x64\" "
}
}
}
The checkout and restore nuget package stages are successful but I am getting an error in the build stage saying :
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5):
error : The package Npgsql with version 4.0.5 could not be found in
C:\Windows\system32\config\systemprofile\.nuget\packages\,
C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages.
Run a NuGet package restore to download the package.
[C:\Users\ramin.bohlouli\.jenkins\workspace\BalanceTestPipeline\trunk\BALANCE\BalanceOptimaConnector\BalanceOptimaConnector.csproj]
However , when going to :
C:\Windows\system32\config\systemprofile\.nuget\packages\
and also
%userprofile%\.nuget\packages
which is the default folder , the package with the version 4.0.5 is there.
It's worth mentioning that I checked inside the following path in visual studio and saw that for my project the npgsql 4.0.5 was installed.
tools > NuGet Package Manager > Manage NuGet packages for solution
What could be the reason and the possible solution?
Found the problem and solved it. The problem is that when MSBuil tries to compile , it looks into
C:\Windows\system32\config\systemprofile\.nuget\packages
which is not based on a x64 platform. So if you use msbuild.exe which is for x64 , the problem is solved.
You can find the x64 version of msbuild.exe in the following path :
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64
I spend 1 day on fixing this problem and I thought it's not something that I can take care of! but sometimes big problems have simple answers.