How to prevent auto-install of Bootstrap (and dependencies) in MVC 5 scaffolding?

后端 未结 2 1610
栀梦
栀梦 2020-12-15 10:14

When I create a new ASP.net MVC 5 project and add a view via scaffolding from a controller\'s action, Visual Studio always adds the Nuget package for Bootstrap and its depen

相关标签:
2条回答
  • 2020-12-15 10:46

    There are a few options that are available and that will satisfy your needs with varying degrees of overhead.

    Use the default template and remove Bootstrap

    • Right-click your project's References and select Manage NuGet Packages...
    • Find the packages that you don't want and Uninstall them.

    This will solve the issue of Visual Studio restoring the files when you build, but does not permanently alter the default template. These dependencies are installed via NuGet, so just deleting the css/js will not remove the dependency your project has on Bootstrap, just the downloaded files. When NuGet does a package restore it is re-downloading the files you deleted, correctly restoring the dependency.

    Export and re-import the default template

    This is basically saving a modified copy of the default template and importing it as a new/different template. This does not modify the default template.

    Similarly to the first suggestion, start a new project with the normal defaults and then uninstall everything you don't want, adjust the HTML and get things the way you want a default MVC template to be.

    After this is done you can export the modified project as a new template following the directions for Customizing Templates.

    Manually edit the default Visual Studio template

    This will permanently modify the default template.

    Default templates are stored in VSINSTALLDIR\Common7\IDE. We're looking for the WebTemplates folder. The folder I used for testing with Visual Studio 2015 (replace 14.0 with 12.0 if using 2013) was located at:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\WebTemplates\MVC\CSharp\1033\MvcBasicApplicationv5.0

    • Navigate to this folder.
    • Open the MvcBasicApplication.cshtml.14.vstemplate file.
    • Look for the <WizardData><packages> node
    • Here you can remove the default dependencies so that they will not be installed when creating a new project.
    • With Bootstrap gone, the html markup will be busted, so you may want to also edit the appropriate files in the Views folder to accomidate.
    0 讨论(0)
  • 2020-12-15 11:04

    You can maybe take a look ate this article: Creating a Custom Scaffolder for Visual Studio

    0 讨论(0)
提交回复
热议问题