防止重新构建designer.cs

本文关键字:构建 designer cs 新构建 | 更新日期: 2023-09-27 18:09:55

我使用的是VS 2015 Pro。我有一个叫做test的形式。test.designer.cs文件包含大约12k+行代码。它包含了许多Telerik控件放在几个选项卡(RadPageViewPage)和许多SplitContainer。在设计模式下打开这个表单需要几秒钟,但这不是问题所在。

场景问题:

  1. 打开test.cs和test.cs [Design]两张卡。
  2. 在test.cs中添加一行代码。( private Int32 x = 0).
  3. 执行构建(Shift+F6)
  4. 利润!... 这次不行,因为构建需要20秒。(

如果你执行相同的操作,但没有打开test.cs [Design],构建将在1秒内完成。

  1. 为什么VS重建designer.cs文件,如果我没有做任何改变的设计模式?
  2. 如何防止这种情况发生?
  3. 对于包含大量控件的大型表单,最佳实践是什么?

编辑1:所以假设designer.cs被重建是错误的。
问题是别的。

我使用devv .exe/log启动VS。
下面是一些可能与我的问题有关的错误:

483  Begin package load [Toolbox Controls Installer Package] {2C298B35-07DA-45F1-96A3-BE55D91C8D7A}  VisualStudio 2015/08/27 08:59:05.832
484  End package load [Toolbox Controls Installer Package] {2C298B35-07DA-45F1-96A3-BE55D91C8D7A}  VisualStudio 2015/08/27 08:59:05.833 
485 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.866 
486 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
487 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
488 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
489 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
490 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
491 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
492 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
493 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
494 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
495 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.867 
496 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
497 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
498 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
499 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
500 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
501 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
502 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
503 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
504 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
505 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
506 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
507 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
508 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.868 
509 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
510 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
511 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
512 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
513 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
514 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
515 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.869 
516 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
517 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
518 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
519 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
520 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
521 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
522 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
523 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
524 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
525 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.870 
526 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
527 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
528 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
529 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
530 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
531 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
532 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
533 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
534 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
535 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
536 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
537 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
538 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
539 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
540 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.871 
541 ERROR Exception parsing Advertised (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
542 ERROR Exception parsing AssemblyFolders (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
543 ERROR Exception parsing Fusion (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
544 ERROR Exception parsing NGen (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
545 ERROR Exception parsing NGenQueue (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
546 ERROR Exception parsing policy (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
547 ERROR Exception parsing Security (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
548 ERROR Exception parsing Windows Presentation Foundation (under HKEY_LOCAL_MACHINE'Software'Microsoft'.NETFramework) as a version   Microsoft.VisualStudio.IDE.ToolboxControlsInstaller.ToolboxInstallerPackage 2015/08/27 08:59:05.872 
549  Done loading new toolbox content, total time = 125 ms

防止重新构建designer.cs

更改。cs文件将触发重新生成设计器文件,这是没有办法的。我建议将您的类再次分段,并将经常修改的代码放在单独的代码文件中。

  1. 在代码视图中修改Form.cs在正常情况下从不修改Form.Designer.cs。它不依赖于打开或关闭设计器视图。Form.cs有2个视图,代码视图和设计器视图。只有在Designer视图中进行更改才会导致Form.Designer.cs重新生成,即使两个视图都是打开的

  2. 不要手动更改Form.Designer.cs或者不要更改设计器视图。一些第三方组件每次在设计器视图中显示表单时都会更改设计器生成的代码,并使其在VS选项卡中显示*。

  3. 把控件放在UserControl和把UserControl放在表单上可能是一个解决方案。如果你为UserControl提供了合适的方法和属性,你就不需要打开UserControl设计器,然后设计器的代码就不会再生成了。

我只是安排了一个包含数百个标准windows窗体控件的窗体测试。设计器文件包含超过14000行代码。我用您描述的状态(以及其他一些状态)测试了打开和更改文件。

  • Form.Designer.cs仅在设计器视图中进行更改时生成。
  • 在Designer视图中工作并进行更改和因此重新生成Form.Designer.cs的成本很高。
  • 在每个状态下构建应用程序的成本是相同的(如果你先保存所有文件)。