简体   繁体   中英

In Visual Studio, how do I debug a project without building it

This is for Visual Studio 2008.

I have Tools|Projects and Solutions|Build and Run|On Run, when projects are out of date set to Always build because that is what I usually want. However, there are some times (when I am examining historic versions in version control) where I want to skip the build process. Is there a magic keystroke that will override the build step for exactly one debugging session so I don't have to change the setting and change it back?

请右键单击解决方案名称并转到Properties -> Configuration Properties -> Configuration ,清除项目的 Build 复选框。

在 VS2013 中,它是:右键单击solution -> Configuration Manager ,然后清除项目的 Build 复选框。

I found it convenient to create a new build configuration in order to do this. Right-click the solution in the Solution Explorer and choose Properties . From there, choose Configuration Properties / Configuration . Now choose Configuration Manager and create a new configuration as shown. You can create the build configuration as a copy of your Debug project:

在此处输入图片说明

Then, press OK and turn off all of the project build flags:

在此处输入图片说明

Visual Studio will have created a folder underneath the bin folder in the startup project with the name of the new configuration. Copy your pre-built files into there and run the new configuration.

I put the following function in my NuGet_profile.ps1 :

function debugnobuild() {
    # temporarily disable build (same as Properties -> Configuration -> ..)
    $buildProjects = @($DTE.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts |
    where ShouldBuild | foreach {
        $_.ShouldBuild = $false
        $_.ProjectName
    })
    try {
        # start debugging
        $DTE.Solution.SolutionBuild.Debug()
    }
    finally {
        # undo changes
        $DTE.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts |
        where { $buildProjects -contains $_.ProjectName } | foreach {
            $_.ShouldBuild = $true
        }
    }
}

Then just call debugnobuild (or any name you prefer) in the Package Manager Console.

我要做的是:在代码中设置System.Diagnostics.Debugger.Launch()行,单独运行程序,在 VS 中附加调试器。

No, there isn't. You can't debug an historic version without running it, which implies building it. VS debugs against the current symbols and binary, which will be out sync with the source without building it, making debugging impossible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM