本文介绍了如何防止在MVC 5脚手架中自动安装Bootstrap(和依赖项)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个新的ASP.net MVC 5项目并通过脚手架从控制器的动作中添加视图时,Visual Studio始终会为Bootstrap及其依赖项(例如jQuery)添加Nuget包.大多数时候,我发现这是多余的,大多数时候,我发现自己将其删除.

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 dependencies (e.g. jQuery). Most of the time I find that this is pretty redundant and most of the time I find myself removing it.

创建项目时是否可以指定一个选项?还是在某个地方有Visual Studio选项可以阻止通过视图脚手架安装Bootstrap?还是让我创建自己的模板来工作?

Is there an option I can specify when creating a project? or is there a Visual Studio option somewhere that will stop Bootstrap from being installed via view scaffolding? or perhaps let me create my own template to work from?

推荐答案

有一些可用的选项,它们会以不同程度的开销满足您的需求.

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

使用默认模板并删除Bootstrap

  • 右键单击项目的References,然后选择Manage NuGet Packages...
  • 找到不需要的软件包,然后将其卸载.
  • Right-click your project's References and select Manage NuGet Packages...
  • Find the packages that you don't want and Uninstall them.

这将解决Visual Studio在构建时还原文件的问题,但不会永久更改默认模板.这些依赖项是通过NuGet安装的,因此仅删除css/js不会删除您的项目对Bootstrap的依赖项,而仅会删除下载的文件. NuGet还原软件包时,它将重新下载您删除的文件,从而正确还原依赖关系.

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.

导出并重新导入默认模板

这基本上是保存默认模板的修改后的副本,并将其作为新模板/不同模板导入.这不会修改默认模板.

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.

类似于第一个建议,使用正常的默认值开始一个新项目,然后卸载不需要的所有内容,调整HTML并按照默认MVC模板的方式进行操作.

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.

手动编辑默认的Visual Studio模板

这将永久修改默认模板.

This will permanently modify the default template.

默认模板存储在VSINSTALLDIR\Common7\IDE中.我们正在寻找WebTemplates文件夹.我用于Visual Studio 2015测试的文件夹(如果使用2013,将14.0替换为12.0)位于

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

  • 导航到该文件夹​​.
  • 打开MvcBasicApplication.cshtml.14.vstemplate文件.
  • 寻找<WizardData><packages>节点
  • 您可以在此处删除默认依赖项,以便在创建新项目时不会安装它们.
  • 在没有Bootstrap的情况下,HTML标记将被删除,因此您可能还需要编辑Views文件夹中的相应文件以使其适合.
  • 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.

这篇关于如何防止在MVC 5脚手架中自动安装Bootstrap(和依赖项)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:23