0

Set up

I have a solution Commons.sln which contain common utils for other more specific projects. Let's take for future example one specific solution called Cars.sln just to make it easier to explore the case. All solutions have their own set of NuGet packages. All projects are laying in the same VCS branch therefore folder structure is pretty strict.

What I want to achieve?

I would like to have references for common libraries in all specific projects. Accordingly, I have added projects from Commons.sln to my Cars.sln. However I met an issue with this setup because people from my team who never built Commons.sln do not have NuGet packages from this solution downloaded to their machines and when the try to build Cars.sln - they face an error saying that dlls for projects from Commons.sln are not found.

Long story short - I would like to execute nuget restore ../../Commons/Commons.sln before build, but do not know how to do it better on Cars.sln solution level on every build/rebuild in Visual Studio.

Specifics

I have done a little research on this and there are my bullet points:

  1. I do not want to commit any of my NuGet packages in VCS
  2. I so a solution with adding a .target file per solution but it works only when I build directly with msbuild.exe.
  3. In other SO question. There is a recommendation to add one more project and resolve it by build order which seems to be hacky to me.

Specific projects are bound to CI server so this stucture should work there as well (currently I have solved by adding a build step that builds Commons.sln before everything else)

Any suggestions are appreciated.

Community
  • 1
  • 1
Oleksii Aza
  • 5,212
  • 27
  • 33

1 Answers1

0

Currently I have fixed it with adding a msbuild target to the project in Commons.sln which is a dependency to all projects including specific ones, like Cars.sln:

<Target Name="Test" BeforeTargets="BeforeBuild">
  <Message Text="Restoring Common Nugets" Importance="high"></Message>
  <Exec Command="nuget restore &quot;$(ProjectDir)..\Avid.Common.sln&quot;" />
</Target>

However if somebody has a better solution I would be glad to know about it.

Oleksii Aza
  • 5,212
  • 27
  • 33