Search code examples
jenkinsvisual-studio-2013msbuildnugetfody

msbuild not restoring only fody nuget package


I am using Stamp.Fody nuget package to stamp my .Net assembly. It has Fody as dependent nuget package. Jenkin is our continuous integration server. In order to build .Net solution MSBuild command line call is used.

Upon running the msbuild command line following error is appearing.

"C:\Source\Demo.sln" (default target) (1) -> "C:\Source\Demo.UI.csproj" (default target) (2) -> C:\Source\Demo.UI.csproj(185,5): error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Fody.1.25.0\build\Fody.targets.

When working with Visual Studio IDE, if either Fody or any other nuget packages are missing then the Visual Studio IDE's package manager itself restoring all the missed packages successfully.

Interestingly if I run MSBuild command line after removing NUnit, Prism and Fody nuget packages and clearing the Nuget package cache, other than Fody nuget package all other packages (NUnit and Prism) are successfully restored. But not Fody.

According to NuGet Package Restore does not fetch Build Target Assemblies (Tools) reference I understood there was a nuget download problem with all Fody nuget packages version prior to 1.13.0.0. Also as advised in that link I added Fody nuget package reference to all the projects in my solution and tried to build the solution but it is again complete build failure. (I have no previous versions installed so no need to remove anything from Tools/Fody folder - as mentioned in the readme.txt)

I have checked all other following known possible cases and end up with no success.

I don't know what I am missing here. Could anyone help me on this please?


Solution

  • The recommended approach for nuget packages is to use the Automatic Package Restore before the build rather than during the build. When using with MSBuild, you can use the restore option (available in Nuget version 2.7 and above) before the actual build starts, which will download all the nuget packages that your solution uses.

    More info can be found at package restore and in particular the section that says Command-Line Package Restore wrapped in MSBuild

    This approach works not only for Jenkins based CI but also for TFS or any other CI servers. Author of the Fody package Simon recommends the same approach