开发者

VS2008 / C# Close all designers when project is compiled?

开发者 https://www.devze.com 2022-12-14 11:36 出处:网络
The C# designers in VS2008 have some issues, e.g. they sometimes \'forget\' a control when the project is compiled. The designer especially tends to forget usercontrols.

The C# designers in VS2008 have some issues, e.g. they sometimes 'forget' a control when the project is compiled. The designer especially tends to forget usercontrols.

I googled a while back to work around this - found this hint: Close all designers before compiling the project.

Does this really help?

And is ther开发者_高级运维e a way to to it automatically? (Pre-Compile-Script etc?)


I don't know if this is what you are looking for, but if you open the command window you can type:

>CloseAll
>Build.BuildSolution


Here is the macro which closes all designers and leaves text files opened:

Sub CloseAllDesigners()
    Dim doc As Document
    For Each doc In DTE.Documents
        Dim win As Window
        For Each win In doc.Windows
            Select Case TypeName(win.Object)
                Case "TextWindow", "HTMLWindow"
                    'keep opened
                Case Else
                    'close
                    win.Close(vsSaveChanges.vsSaveChangesPrompt)
            End Select
        Next
    Next
End Sub

See my quick tutorial how to create and execute VS macro and assign a keybord shortcut or button to it. You can even automatically execute this macro before each build. In the Macros IDE Class View navigate to MyMacros - EnvironmentEvents. Open (double-click) EnvironmentEvents. Insert the following code inside module:

Private Sub BuildEvents_OnBuildBegin( _
  ByVal Scope As EnvDTE.vsBuildScope, _
  ByVal Action As EnvDTE.vsBuildAction) _
  Handles BuildEvents.OnBuildBegin

    CloseAllDesigners()
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号