生成警告与 IntelliSense 警告
Build warnings vs IntelliSense warnings
我刚加入一家有遗留代码的公司。
该构建有超过 10000 个警告。
90% 的警告是 "obsolete" 警告。
我的同事不希望我禁用这些警告,因为它在 IntelliSense 中对他们很有用。
我的问题是:有没有一种实用的方法,我仍然可以在 Visual Studio 的编辑器中看到警告,但它不会出现在 build.log 中?
我认为您需要在构建配置 "Debug" 和 "Release" 之间切换。因此,在编译 "Release" 时,您将能够得到 "clean" build.log,但在使用 "Debug" 构建时仍然会收到警告:
当你自己工作时,你只需要取消选中错误列表面板中的警告:
这里有一些基本的 SWDev 逻辑:
如果警告有用,则应将其修复为错误(可能是小错误)。
如果警告无用,则应将其抑制以保持构建清洁,以便显示有用的警告。
最终,由于项目进度和管理压力,可能无法将这样的技术债务减少到可管理的程度。但是禁用正确且有用的警告是一个非常糟糕的主意(尤其是抑制过时的警告 - 相关组件的下一次升级将导致产品停止工作,需要大量的工作来修复它)。
在我工作的地方,我们通常对这类事情做的是将它们作为开发计划中的任务优先考虑 - 我们会开会,决定哪些问题很重要(哪些警告需要去追求,压制等等...),并将它们分成许多任务,并具有适当的优先级。
Is there a practical way, where i can still see the warning in the editor in visual studio, but it does not show up in the build.log?
由于您无法禁用这些警告并且使用 #pragma warning disable
不是您的选择,我想为您提供解决此问题的解决方法。
您可以通过 MSBuild 命令行 /p:WarningLevel=X
设法抑制警告级别。
例如,当我从 Visual Studio 构建示例项目时,错误列表中有警告 window:
然后我使用 MSBuild 命令行构建它,在命令行中使用 属性 /p:WarningLevel=0
:
msbuild "YourProjectName" /fl /flp:logfile=D:\MyProjectOutput.log;verbosity=diagnostic /p:WarningLevel=0
等级含义:
Warning
Level Meaning
-------- -------------------------------------------
0 Turns off emission of all warning messages.
1 Displays severe warning messages
2 Displays level 1 warnings plus certain, less-severe warnings, such
as warnings about hiding class members
3 Displays level 2 warnings plus certain, less-severe warnings, such
as warnings about expressions that always evaluate to true or false
4 (the default) Displays all level 3 warnings plus informational warnings
构建日志中没有警告,然后打开日志文件,这里也没有警告:
希望这对您有所帮助。
我刚加入一家有遗留代码的公司。 该构建有超过 10000 个警告。 90% 的警告是 "obsolete" 警告。 我的同事不希望我禁用这些警告,因为它在 IntelliSense 中对他们很有用。
我的问题是:有没有一种实用的方法,我仍然可以在 Visual Studio 的编辑器中看到警告,但它不会出现在 build.log 中?
我认为您需要在构建配置 "Debug" 和 "Release" 之间切换。因此,在编译 "Release" 时,您将能够得到 "clean" build.log,但在使用 "Debug" 构建时仍然会收到警告:
当你自己工作时,你只需要取消选中错误列表面板中的警告:
这里有一些基本的 SWDev 逻辑:
如果警告有用,则应将其修复为错误(可能是小错误)。 如果警告无用,则应将其抑制以保持构建清洁,以便显示有用的警告。
最终,由于项目进度和管理压力,可能无法将这样的技术债务减少到可管理的程度。但是禁用正确且有用的警告是一个非常糟糕的主意(尤其是抑制过时的警告 - 相关组件的下一次升级将导致产品停止工作,需要大量的工作来修复它)。
在我工作的地方,我们通常对这类事情做的是将它们作为开发计划中的任务优先考虑 - 我们会开会,决定哪些问题很重要(哪些警告需要去追求,压制等等...),并将它们分成许多任务,并具有适当的优先级。
Is there a practical way, where i can still see the warning in the editor in visual studio, but it does not show up in the build.log?
由于您无法禁用这些警告并且使用 #pragma warning disable
不是您的选择,我想为您提供解决此问题的解决方法。
您可以通过 MSBuild 命令行 /p:WarningLevel=X
设法抑制警告级别。
例如,当我从 Visual Studio 构建示例项目时,错误列表中有警告 window:
然后我使用 MSBuild 命令行构建它,在命令行中使用 属性 /p:WarningLevel=0
:
msbuild "YourProjectName" /fl /flp:logfile=D:\MyProjectOutput.log;verbosity=diagnostic /p:WarningLevel=0
等级含义:
Warning
Level Meaning
-------- -------------------------------------------
0 Turns off emission of all warning messages.
1 Displays severe warning messages
2 Displays level 1 warnings plus certain, less-severe warnings, such
as warnings about hiding class members
3 Displays level 2 warnings plus certain, less-severe warnings, such
as warnings about expressions that always evaluate to true or false
4 (the default) Displays all level 3 warnings plus informational warnings
构建日志中没有警告,然后打开日志文件,这里也没有警告:
希望这对您有所帮助。