I am working on a large ASP.NET web application running on .NET Framework 4.8.
Nuget package management is done using with the packages.config
format. There are 150+ nuget package references defined in the web project alone. Some of these are backend concerns, e.g.
<package id="FluentValidation" version="x.y.z" targetFramework="net48" />
Others are front end specific:
<package id="jQuery" version="x.y.z" targetFramework="net48" />
The installed nuget packages for the whole solution live in a packages
directory at solution level, as expected. Installing or updating "front end" packages results in files being copied from the relevant nuget package folders' content directories into the Web Application's project folder, also as expected. Typically these are in folders called scripts
, fonts
and content
.
The contents of the three directories consists of tens of thousands of files and is in source control. I would like to remove them.
The specific problem I am trying to solve is that building the solution with visual studio copies the appropriate binaries and configuration files for the back end packages to the bin folder but none of the front end content.
Unsurprisingly, if this content is removed locally, then this results in run-time errors. Even if these folders are added to gitignore
, committing removal of these files would cause issues for fellow developers cloning the repository for the first time or pulling updates to certain nuget packages.
If the developer is aware that re-installation is required, then this can be achieved with the command:
Update-Package -reinstall -Project YourProjectName
but this takes around 3 minutes due to the total number of packages that are referenced. None of the backend packages need re-installing.
I'm looking for a solution that involves developers being able pull changes, build and debug without having to know or care about front end packages version changes nor having to perform manual installation. Ideally this would just involve a change to the .csproj
file.
I have been unable to find a built-in feature to achieve the suggested outcomes listed below:
Solution 1 (unacceptable): force re-install of all the project's packages on each build using
Update-Package -reinstall
. This would add around 3 minutes to each build, including on the build server.Solution 2: force re-install of selected packages on each build - in the title of the question which I am willing to edit
Solution 3: detect which front end packages are correctly installed on each build and only re-install those that are faulty (e.g. if one file was deleted from the
scripts
folder)Solution 4: pre or post-build event (or targets in the
.csproj
file) to copy files from a subset of the package contents. This would still rely on developers who add/update/remove any package to update a script - maybe not for updates if wildcards are used
Other potential solutions are welcome. Alternatives that have been discounted:
- updating to .NET 8 / 9: too difficult or time consuming, there are some other very large projects in the solution, all .NET Framework
- using a different package manager, e.g. npm: as I understand it, the developer would still need to know that running
npm i
is needed, so it doesn't really address the requirement of developers being able to check something out and press F5
I am aware of the concept of duplicate questions. I have tried to look for a solution myself. Obviously searches including terms like "nuget", "package", "install" and "build" throw up a lot of related content that does not address my specific situation, although I can't be the first person trying to do this.
Related questions:
- How do I get NuGet to install/update all the packages in the packages.config? Answers for installation outside of build, not for specific packages
- ASP.NET web application is not creating a scripts folder .Net Core vs .Net Framework concern
- Why do Nuget Javascript packages copy to Scripts folder Philosophical
- How install Nuget package when building project in Visual Studio Sounds like what I want but this is for a package publisher, not a consumer
- How do I get NuGet to install/update all the packages in the packages.config? Very old. Failing some simple way, I want to install just some packages
EDIT #1: Example Scenario
- Create a new project in Visual Studio. Select "ASP.NET Web Application (.NET Framework)" template. Accept all other defaults
- Inspect the
packages.config
file, observe that it contains package references to e.g.Newtonsoft.Json
andbootstrap
- Press
F5
and run the project until the home page loads. - Stop it, go to the bin folder and delete
Newtonsoft.Json.dll
- Press
F5
again, inspect the bin folder and observe howNewtonsoft.Json.dll
has been copied back in by MsBuild.exe - Now delete all of the bootstrap files in the
Content
folder, simulating another developer pulling the repository with package references inpackages.config
but none of the package installation artefacts - Press
F5
, and observe how the default webpage loads without any of the nice styling. This is the sort of scenario I am trying to avoid. Inspect theContent
folder, it's still empty - Uninstall bootstrap with the package manager and then re-install it. Observe how the
Content
folder is populated once more. PressF5
and observe how the default webpage is beautified once again.
Current behaviour: one developer updates packages with the package manager and commits everything to source control. Other developers pull changes and carry on working without issue
Desired behaviour: one developer updates packages with the package manager and commits only changes in the packages.config
file. Other developers pull changes and carry on working without issue.
Anticipated behaviour: one developer updates packages with the package manager and commits only changes in the packages.config
file. Other developers pull changes and potentially encounter issues because some of the package content hasn't been copied into the Web project
EDIT #2:
Unfortunately, I have learnt that some of these content folders do actually include some specific code that isn't from any nuget package, i.e. written in-house. There are over 16k files involved, going through them all is too much effort and risk, therefore I am going to leave nuget artefacts in source control for now. I'm leaving this question open as I still think an out of the box solution may exist.