views:

38

answers:

2

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 there a way to to it automatically? (Pre-Compile-Script etc?)

+2  A: 

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
klausbyskov
Is it possible to close only the designers? Something like 'Close if windows.type == designer' and put this into a Pre-Build-Script.
Simon Ottenhaus
+1  A: 

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
Peter Macej