0

I have a solution that consists of both single-target and multi-target projects. The solution can be built in Visual Studio 2017 and Developer Command Prompt for VS 2017 without problems.
I build the solution by below code in Developer Command Prompt for VS 2017

msbuild MySolution.sln /t:Rebuild /p:Configuration=Release

I want to do this process in Jenkins. Then I added below command to Jenkins.

pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools"
call VsDevCmd.bat
msbuild "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release

When I build the Jenkins project it throws an exception.

C:\Program Files\dotnet\sdk\2.1.101\Sdks\Microsoft.NET.Sdk\build\
Microsoft.PackageDependencyResolution.targets(327,5): error : Assets file 
'C:\Workspace\My Solution\Source\MyProject\obj\project.assets.json' not found.
Run a NuGet package restore to generate this file. 

Thanks a lot

sabandurna
  • 86
  • 9

2 Answers2

1

Visual Studio usually will do the nuget package restore for you (It can be turned off in settings).

Building the solution from the command line is a different story. You are not using visual studio, but rather plain old MSBuild. MSBuild does not know about your nuget package.

So you have to manually restore your nuget packages first.

pushd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools"
call VsDevCmd.bat
nuget restore "C:\Workspace\My Solution\MySolution.sln"
msbuild "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release
C.J.
  • 15,637
  • 9
  • 61
  • 77
  • I tried your suggested solution, then the assets problem is solved. But now I got a new problem that is error CS0246: The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) – sabandurna Mar 20 '18 at 06:43
  • Sounds like you need to clean up your references. – C.J. Mar 20 '18 at 15:09
0

Jenkins cannot recognize msbuild command. When I change the code like below it started working.

C:\nuget.exe restore "C:\Workspace\My Solution\MySolution.sln"
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe"  "C:\Workspace\My Solution\MySolution.sln" /t:Build /p:Configuration=Release;VisualStudioVersion=15.0

I added nuget restore command and changed msbuild command with full path of msbuild.exe. Finally I put VisualStudioVersion as a parameter.

Thanks @c-johnson

sabandurna
  • 86
  • 9