I am trying to understand if there is any way to rely on Nuget Automatic Package Restore when referencing libraries hosted on Github. The problem is that when I add certain library as submodule, it has it's own /packages/ directory. But, when I add csproj from that library into my solution since there are no DLLs in /packages/ directory of that submodule, build fails.
Obviously, easy fix on my machine is to open up .sln file from submodule that I've referenced, do a build. Now, building from my main solution will obviously work since /packages/ folder in submodule is populated. But, this is not something I can do on build server.
Any way of solving this problem without completely messing up submodule? I obviously also don't want to change submodule .csproj because that would put it out of sync with origin. Ideally I would love if I could instruct nuget to pull packages for referenced submodule .csproj in it's own /packages/ directory.
There are two types of automatic package restore. One that is triggered when you build a solution within Visual Studio, and one that is MSBuild based and requires modifying your project to run NuGet.exe restore as part of the build. The MSBuild based restore is enabled by selecting Enable NuGet Package Restore, but this has been deprecated by the NuGet team.
For a build server you would need to do either:
NuGet.exe restore
for all solutions before you run the build.To restore the NuGet packages with MSBuild you can use the deprecated MSBuild based NuGet package restore or perhaps better is to create a Before.YourSolution.sln.targets file as described in the Ultimate Cross Platform NuGet Restore post. The custom Before....targets file would need to restore packages for the submodule.
If you use an MSBuild based restore then one of the benefits is that there is no pre-build step that someone needs to run before building the solution since building the solution does the restore. One of the problems of the MSBuild based package restore, at least with the one that is enabled when selecting Enable NuGet Package Restore in Visual Studio, is that it can cause problems with NuGet packages that use their own custom MSBuild .targets files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With