4
votes

I'm trying to build a solution on a Jenkins with the MSBuild extension. I've migrated the solution from VS 2013 to VS 2015. To be able to restore the NuGet Packages in Visual Studio 2015 I had to remove the .nuget folder as recommended here: http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore.

Now the issue is that MSBuild needs the .nuget folder to be able to restore the nuget packages.

Build FAILED.

"E:\_JENKINS\workspace\Project1 - Deploy DEVELOP to BuildServer\Solution1\Build\Build.proj" (DeployTarget target) (1) ->
E:\_JENKINS\workspace\Project1 - Deploy DEVELOP to BuildServer\Solution1\Build\Build.proj(50,5): 
error MSB4019: The imported project "E:\_JENKINS\workspace\Project1 - Deploy DEVELOP to BuildServer\Solution1\.nuget\NuGet.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

0 Warning(s)
1 Error(s)

Have I mixed up things? Do I do something completely wrong?
Because only one works: either MSBuild or Studio Package Restore.

So either I'm adding the packages folder to git or replace the automatic restore in the solution by a command line restore or MSBuild restore. But anyway both solutions seem to be wrong.

1
Simply remove the reference to that targets file from your project files (csproj) and then use nuget restore solution.sln to restore the packages before compiling. NuGet documentation has more about such migration. - Lex Li

1 Answers

0
votes

The way NuGet Package Restore works changed between Visual Studio 2013 and 2015.

The first step in your build process needs to be a direct call to NuGet.exe like:

nuget restore solution.sln

I put NuGet.exe in the PATH on my build machine.

You should see in the console (or pipeline step log) the packages being restored.

If not, you may need to look at the Jenkins proxy settings, depending on where your Jenkins is on the network in relation to the internet. In the past I have had to request a service account with "privileged" access to nuget.org/*

Once all packages have been restored you should see a packages/ folder as a sibliing to your solution file in the Jenkins workspace.

You can then call MSBuild with /t:Clean and /t:Rebuild in turn and expect to get past the NuGet package step.