If you have decided on Checking in Package Dependencies into Source Control for an existing project that uses Nuget Packages then this post is for you
When using NuGet package references that are not included in the source control, these packages gets restored during build time. There are multiple ways that NuGet supports restore these dependencies at build time
- Automatic Package Restore is the current recommended approach (within Visual Studio), which is available from NuGet 2.7.
- Command-line package restore on build servers
- MSBuild-integrated package restore approach is the original Package Restore implementation and is still used in many projects.
Depending on the type to of restore the project uses, NuGet has different configuration entries in the csproj files and .nuget folder in the solution root. So when choosing to check in package dependencies into the source control, it is a good idea to remove all these generated configurations and files that are not required any more. The below script does this for you!
The PowerShell script does the below for a given solution directory folder (mandatory)
- For each of the csproj file in the given folder, the script removes the
- RestorePackages node
- NugetPackageImportStamp node
- nuget target import from the solution root .nuget folder
- EnsureNuGetPackageBuildImports node
- Removes .nuget folder from the solution root if it exists.
The script leaves blank lines in the csproj files in place of the removed nodes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
1 2 3 4 5 6 7 8 9 10
Hope this helps you to move away from NuGet restore at build time.