问题
Note, that I am not talking about msbuild output verbosity, but about devenv - the IDE:
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
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?
EDIT 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]
}
Please, observe:
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:
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
...
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
What am I missing?
EDIT 2
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
Now what?
EDIT 3
Here is my code to set it:
$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
}
来源:https://stackoverflow.com/questions/63046302/how-to-change-the-visual-studio-build-output-verbosity-through-scripting