如何通过脚本更改 Visual Studio 构建输出详细程度? [英] How to change the Visual Studio build output verbosity through scripting?

查看:30
本文介绍了如何通过脚本更改 Visual Studio 构建输出详细程度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,我不是在谈论 msbuild 输出的详细程度,而是在谈论 devenv - IDE:

Note, that I am not talking about msbuild output verbosity, but about devenv - the IDE:

它为此使用注册表.然而,在 VS 2015 中,注册表项很清楚,下面的简单脚本完成了这项工作:

It uses registry for that. However, in VS 2015 the registry keys were clear and the following simple script did the job:

Param(
  [Parameter(Mandatory)][ValidateRange(1,4)][int]$level
)

$path = "HKCU:\Software\Microsoft\VisualStudio\14.0\General"

Set-ItemProperty -Path $path -Name MSBuildLogFileVerbosity -Value $level -Type DWord
Set-ItemProperty -Path $path -Name MSBuildLoggerVerbosity -Value $level -Type DWord

在 VS 2019 中,注册表路径包含一个 guid,密钥本身看起来有点奇怪.所以,这是我提问的机会 - 有没有更好的编程方式来做到这一点?

In VS 2019 the registry path contains a guid and the key itself looks kind of weird. So, this is my opportunity to ask - is there a better way to do it programmatically?

编辑 1

所以我阅读了评论中引用的帖子并想出了以下功能:

So I read the posts referenced in the comments and came up with the following function:

$VSBuildVerbosityLevels = @(
    'quiet',
    'minimal',
    'normal',
    'detailed',
    'diagnostic'
)
function Get-VSBuildVerbosity
{
    [CmdLetBinding()]
    param()
    $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
    $installPath = & $vsWhere -latest -property installationPath
    $vsregedit = "$installPath\Common7\IDE\vsregedit.exe"

    $cmd = "& `"$vsregedit`" read local HKCU General MSBuildLoggerVerbosity dword"
    Write-Verbose $cmd
    $Level = (Invoke-Expression $cmd).Substring('Name: MSBuildLoggerVerbosity, Value: '.Length)
    $VSBuildVerbosityLevels[$Level]
}

请注意:

C:\> Get-VSBuildVerbosity -Verbose
VERBOSE: & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\vsregedit.exe" read local HKCU General MSBuildLoggerVerbosity dword
minimal
C:\>

但它似乎没有返回正确的结果:

But it does not seem to return the right result:

VS 版本应该是正确的:

The VS version is supposed to be correct:

Microsoft Visual Studio Enterprise 2019
Version 16.6.3
VisualStudio.16.Release/16.6.3+30225.117
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Enterprise

...

根据 procmon,更改 IDE 中的值会影响以下注册表项:

According to procmon, changing the value in the IDE affects the following registry key:

\REGISTRY\A\{a7e8587a-40a4-a5b0-0119-e9050f63198a}\Software\Microsoft\VisualStudio\16.0_44c67ac6\General\MSBuildLoggerVerbosity

我错过了什么?

编辑 2

运行 procmon 显示 VS IDE 和 vsregedit 接触不同的注册表项:

Running procmon reveals that VS IDE and vsregedit touch different registry keys:

  • VS IDE - \REGISTRY\A\{a7e8587a-40a4-a5b0-0119-e9050f63198a}\Software\Microsoft\VisualStudio\16.0_44c67ac6\General\MSBuildLoggerVerbosity
  • vsregedit - \REGISTRY\A\{d8a7e391-9143-745b-e649-9339d4390cfe}\Software\Microsoft\VisualStudio\16.0_44c67ac6\General\MSBuildLoggerVerbosity

现在怎么办?

编辑 3

这是我设置它的代码:

$VSBuildVerbosityLevelMap = @{ }
$VSBuildVerbosityLevels | ForEach-Object { $i = 0 } {
    $VSBuildVerbosityLevelMap[$_] = $i
    ++$i
}
function Set-VSBuildVerbosity(
    [Parameter(Mandatory)][ValidateSet('quiet', 'minimal', 'normal', 'detailed', 'diagnostic')]$Level
)
{
    $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
    $installPath = & $vsWhere -latest -property installationPath
    $vsregedit = "$installPath\Common7\IDE\vsregedit.exe"

    $cmd = "& `"$vsregedit`" set local HKCU General MSBuildLoggerVerbosity dword $($VSBuildVerbosityLevelMap[$Level])"
    Write-Verbose $cmd
    $null = Invoke-Expression $cmd
}

编辑 4

这真的很好奇.我正在使用我的函数来设置详细程度,它似乎正在工作,但 Visual Studio 对话框似乎无法识别它!观察:

This is really curious. I was using my function to set the verbosity and it appears to be working, BUT the Visual Studio dialog does not seem to recognize it! Observe:

构建输出诊断信息,但构建和运行属性表告诉我们构建输出详细程度最低!

The build outputs diagnostics, but the Build And Run property sheet tells us the build output verbosity is Minimal!

这让我大吃一惊——Powershell 代码似乎正确设置了详细程度,但构建和运行"选项对话框似乎报告了不同的值!

That is what sets me aback - the Powershell code appears to set the verbosity correctly, but the Build and Run options dialog seems to report a different value!

推荐答案

Visual Studio 包含一个 vsregedit.exe 实用程序,可用于更改 Visual Studio 设置:

Visual Studio includes a vsregedit.exe utility that you can use to change Visual Studio settings:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VsRegEdit.exe" set local HKCU General MSBuildLoggerVerbosity dword 4

这篇关于如何通过脚本更改 Visual Studio 构建输出详细程度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆