Search code examples
.net-corenuget

RestorePackagesWithLockFile in multi module project


Dotnet Core, and more specifically the NuGet package management part of dotnet support the RestorePackagesWithLockFile option to allow freezing of package dependencies with lock files. This is similar to how this is done in NPM.

However, in npm the lockfile generation is the default, while it seems in NuGet we need to enable this explicitly in each .csproj file. Is there any option to enable this by default for all nested projects of a given solution that are contained in a git repository? It feels unintuitive that I need to put this option into each source module (as well as test modules) that I have in my project. Also if we add further modules in the futures then people will need to remember to add this option as well.


Solution

  • You can add Directory.Build.props file to your solution folder with this property.

    Documentation about Directory.Build.props and Directory.Build.targets