简体   繁体   中英

Solution builds in Visual Studio but Jenkins throws an assets exception

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM