visual-studio 如何在 Visual Studio 中不调试的情况下启动单个项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1356565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:56:32  来源:igfitidea点击:

How to start a single project without debugging in Visual Studio?

visual-studio

提问by Oliver Hanappi

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.

我的解决方案包含多个可以启动的项目。有时我想在不使用我的解决方案启动项目设置的情况下启动单个项目。当我右键单击该项目时,我可以导航到 Debug->Start New Instance,这将使用调试器启动应用程序。

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

但我想在没有调试器的情况下启动一个新实例。这可能吗?

采纳答案by MRG

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.
  1. 获取当前选定的项目(如果您选择了多个项目,它将使用第一个选定的项目。)
  2. 保存当前启动项目
  3. 将当前选定的项目设置为启动项目,并在“不调试启动”模式下运行当前选定的项目。
  4. 将初始启动项目恢复为启动项目。

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).

如何编写宏:首先需要转到 Visual Studio 工具 --> 宏 --> 宏资源管理器。右键单击 MyMacros 并创建一个新模块(我将其称为 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.

如何将宏绑定到键盘快捷键:为此,您需要转到工具--> 选项--> 环境--> 键盘。从带有所有默认 VS 内容的列表框中选择您的宏(记住它会像 MyMacros.Module1.RunSelectedWithoutDebug 一样在那里),然后为其分配一个热键组合或和弦并保存。

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.

注意:第四步是创建一个问题并产生一个烦人的消息框说:必须停止构建以更改解决方案属性。停止构建?确定或取消。我曾经暂时打好。如果宏将当前选定的项目设置为启动项目没有任何问题,请通过将 ' 放在行的开头来评论宏 Prop.Value = PrevStartup 的最后一行。现在消息框不会出现。

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

我正在研究它,一旦我解决它就会发布更新的宏(如果可以的话:))

回答by xhafan

Add VSCommandsextension into Visual Studio, right click a project -> Debug -> Start Without Debugging

VSCommands扩展添加到 Visual Studio 中,右键单击一个项目 -> Debug -> Start withoutDebugging

回答by Srekel

Maybe this is new in VS 2015 but there's no need to add a custom macro - you can find the Start Without Debugging menu item in the list of things you can add.

也许这是 VS 2015 中的新功能,但无需添加自定义宏 - 您可以在可以添加的内容列表中找到“开始而不调试”菜单项。

Go to Tools -> Customize, follow the images below.

转到工具 -> 自定义,按照下图操作。

Hit Add CommandHere you can find the menu item

点击添加命令在这里您可以找到菜单项

回答by Alex Dresko

I just put together this macro.. It's a combination of several snippets I found around the interweb. If the project is configured to run the default project output, it will find and run that. If it's configured to run a specific program, it will run that. This macro will NOT compile your application either, so you'll want to make sure it's compiled before you run the macro. At the same time, this macro doesn't suffer from the problem mentioned in Mahin's macro above.

我只是把这个宏放在一起..它是我在互联网上找到的几个片段的组合。如果项目配置为运行默认项目输出,它将找到并运行该输出。如果它配置为运行特定程序,它将运行该程序。此宏也不会编译您的应用程序,因此您需要在运行宏之前确保它已编译。同时,这个宏没有遇到上面马欣宏中提到的问题。

Sub RunActiveProjectOutput()
    Dim Projs As Array
    Dim Proj As Project
    Projs = DTE.ActiveSolutionProjects()
    If (Projs.Length > 0) Then
        Proj = Projs.GetValue(0)

        Dim action = DirectCast(Proj.ConfigurationManager.ActiveConfiguration.Properties.Item("StartAction").Value, Integer)

        If (action = 1) Then
            Dim app = Proj.ConfigurationManager.ActiveConfiguration.Properties.Item("StartProgram").Value
            Dim args = Proj.ConfigurationManager.ActiveConfiguration.Properties.Item("StartArguments").Value
            System.Diagnostics.Process.Start(app, args)
        Else
            Dim fullPath = Proj.Properties.Item("FullPath").Value.ToString()
            Dim outputPath = Proj.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString()
            Dim outputDir = System.IO.Path.Combine(fullPath, outputPath)
            Dim outputFileName = Proj.Properties.Item("OutputFileName").Value.ToString()
            Dim assemblyPath = System.IO.Path.Combine(outputDir, outputFileName)
            System.Diagnostics.Process.Start(assemblyPath)
        End If
    End If
End Sub

回答by Micz

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 !

享受 !

回答by CodingWithSpike

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.

我一直在尝试做同样的事情。这似乎是 VS 团队的疏忽,您可以在解决方案级别进行或不进行调试,但只能在项目级别进行调试。

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 alwaysbe 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!

希望有人想出一个好方法来做到这一点......它真的很方便!

回答by rahul

Use Start without debuggingunder Debug menu, or

在 Debug 菜单下使用Start without debugging,或

Ctrl+F5

Ctrl+F5

or you can modify the web.config file for the project:

或者您可以修改项目的 web.config 文件:

<compilation debug="false"/>

回答by Aamir

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

右键单击项目并将其设置为启动项目。

Hit Ctrl + F5

按 Ctrl + F5

回答by Robban

In short no.

总之没有。

What you could do is bind a key to the "Set as startup project" and then bind another key to start without debugging. Then you would have to push 2 keys to start this project without debugging, but at least it'd be quicker than using the mouse...

您可以做的是将一个键绑定到“设置为启动项目”,然后绑定另一个键以启动而无需调试。然后你将不得不按 2 个键来启动这个项目而不进行调试,但至少它比使用鼠标更快......

回答by Jim O'Keefe

This is pretty quick: Project | Set As StartUp Project | Current Selection. Then whichever project is selected is run under Debug | Start Without Debugging / Ctrl-f5. https://blogs.msdn.microsoft.com/saraford/2005/11/29/how-to-set-your-current-project-to-always-be-the-startup-project/

这很快:项目 | 设为启动项目 | 当前选择。然后无论选择哪个项目都在 Debug | 下运行。不调试启动/Ctrl-f5。 https://blogs.msdn.microsoft.com/saraford/2005/11/29/how-to-set-your-current-project-to-always-be-the-startup-project/