Search code examples
c#visual-studiomsbuildnugetpre-build-event

Update nuget package for ASP.NET Web Application


When I create a ASP.NET Web Application (.net framework), there are dozens of packages are installed by default. In the development of our projects, we need to update some of those default nuget packages.

I know I could use nuget update in the Package Manager Console to update them. However, when we create the new projects, we need to remember which packages need to be upgraded. This is very inconvenient.

So my question is whether there is a way to update the list of specific packages so that we do not need to update it each time when we create the new project? Whether I could use Pre-build event to achieve what I want?


Solution

  • whether there is a way to update the list of specific packages so that we do not need to update it each time when we create the new project?

    Agree with Yuri S. The best way to resolve this question is using project template.

    Detail Steps:

    1. Create a default ASP.NET Web Application (.net framework) project.

    2. Update those packages which you want to upgrade.

    3. Export Template. (For VS2015 and before, File->Export Template... For VS 2017, Project->Export Template)

    4. You can find the new project template in your template list.

    enter image description here

    Note: Make sure the checkbox "Automatically import the template into Visual Studio" is checked in the export template wizard window.

    enter image description here

    Whether I could use Pre-build event to achieve what I want?

    I am afraid you can not do this with pro-build event. That because you just want to upgrade some of default packages not all default packages. When you use the update command nuget.exe update "xx" in the build event, nuget will prompt that you need give the package.config, project.json or solution file. So it will upgrade all default packages.

    Besides, with this build event, Visual Studio will execute the upgrade every time when you build you project, which is unreasonable.

    So the best way is using project template.