How to start a single project without debugging in

2019-01-10 18:37发布

My solution contains multiple projects which can be started. SometimesI would like to start a single project without using my solution startup projects settings. When I right-click on the project, I can navigate to Debug->Start New Instance, which starts the application with debugger.

But I would like to start a new instance without debugger. Is this possible?

14条回答
我只想做你的唯一
2楼-- · 2019-01-10 18:44

Right-Click on the project and Set it as Startup Project.

Hit Ctrl + F5

查看更多
迷人小祖宗
3楼-- · 2019-01-10 18:45

Here is the the way to solve problem related to Mahin's macro

Problem description: Fourth step is creating a problem and spawns an annoying messagebox saying : The build must be stopped to change the solution property. Stop the build? Ok or Cancel.

Public Module Custom
    Private WithEvents t As Timers.Timer

    Private Prop As EnvDTE.Property
    Private PrevStartup As Object

    Private Sub StartTimer()
        t = New Timers.Timer
        t.Interval = 0.05
        t.Start()
    End Sub

    Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed
        If DTE.Solution.SolutionBuild.BuildState <> vsBuildState.vsBuildStateInProgress Then
            t.Stop()
            Prop.Value = PrevStartup
        End If
    End Sub

    Sub RunSelectedWithoutDebug()
        Dim Projs As Array
        Dim Proj As Project
        Projs = DTE.ActiveSolutionProjects()
        If (Projs.Length > 0) Then
            Proj = Projs.GetValue(0)
            Prop = DTE.Solution.Properties.Item("StartupProject")

            PrevStartup = Prop.Value
            Prop.Value = Proj.Name
            DTE.ExecuteCommand("Debug.StartWithoutDebugging")
            StartTimer()
        End If
    End Sub
End Module

Enjoy !

查看更多
叼着烟拽天下
4楼-- · 2019-01-10 18:45

I usually start the executable directly. If i need one solution without debugging mode a lot i usually add them to a quick launch menu somewhere on my taskbar.

查看更多
做个烂人
5楼-- · 2019-01-10 18:46

If you are interested in permanent solution then I have written a small macro for this task. It does following things :

  1. Gets current selected project ( it will use first selected project, if you have selected multiple projects.)
  2. Saves the current Startup Project
  3. Sets the current selected project as Startup project and Runs the current selected project in "Start without Debug" Mode.
  4. Restores the Initial Startup Project as Startup Project.

Below is the Macro that I have written and the procedure how to do it.

How to write Macro : First thing you need to go to Visual Studio Tools --> Macros --> Macro Explorer. Once you got that right click on MyMacros and create a new module (I called it CollapseAll).

Now edit the new module (double-click on it) erase whatever is in there and paste this stuff into it.

Sub RunSelectedWithoutDebug()
            Dim Projs As Array
            Dim Proj As Project
            Projs = DTE.ActiveSolutionProjects()
            If (Projs.Length > 0) Then
                Proj = Projs.GetValue(0)
                Dim Prop As EnvDTE.Property
                Prop = DTE.Solution.Properties.Item("StartupProject")
                Dim PrevStartup As Object
                PrevStartup = Prop.Value
                Prop.Value = Proj.Name
                DTE.ExecuteCommand("Debug.StartWithoutDebugging")
                Prop.Value = PrevStartup
            End If
        End Sub

How to bind macro to keyboard shortcut : To do this you need to go to Tools-->Options-->Environment-->Keyboard. Pick your macro from the listBox with all the default VS stuff (remember it will be there like MyMacros.Module1.RunSelectedWithoutDebug) and then assign a hotkey combination or chord to it and save.

Note : Fourth step is creating a problem and spawns an annoying messagebox saying : The build must be stopped to change the solution property. Stop the build? Ok or Cancel. I used to hit Ok for the timebeing. If you dont have any problem if the macro sets up current selected project as Startup project than please comment last line of macro Prop.Value = PrevStartup by putting ' at the start of line.Now the messagebox will not come.

I am looking into it and will post the updated macro once i solve it ( if I can :) )

查看更多
贼婆χ
6楼-- · 2019-01-10 18:54
  1. Set the required project to be the Startup Project (as every has suggested)
  2. Turn off 'Build' for all other projects in the Solution Configuration Manager
  3. Start Without Debugging.
查看更多
迷人小祖宗
7楼-- · 2019-01-10 18:59

I've been trying to do the same thing. It seems like an oversight by the VS team that you can start with or without debug at the solution level, but only with debug at the project level.

One thing that I've noticed is that if you right-click on a toolbar and choose "Customize", in the popup window of actions, go to Category "Project". In there, there is a command for "Run" and "Run Selected". Interesting, I added both to my project context menu, and to the main button bar, and the items seem to always be disabled.

Also interesting, the project context menu's "Debug | Start New Instance" command is nowhere to be found in the list of customizable commands. I looked through almost every category and couldn't find it.

Hopefully someone comes up with a good way to do this... it would be really handy!

查看更多
登录 后发表回答