Warn-as-error for MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved

StackOverflow https://stackoverflow.com/questions/23662639

  •  22-07-2023
  •  | 
  •  

Вопрос

After I have fixed this warning, how can I make it an error, so it doesn't slip in again?

msbuild /p:TreatWarningsAsErrors doesn't work

Это было полезно?

Решение

No happy answer to give you here. The TreatWarningsAsErrors property only affects the C# and VB.NET compiler (not C++), it determines the value of their /warnaserror command line option.

But MSB3277 is generated by an MSBuild task, ResolveAssemblyReference, its internal LogResult() method generates the diagnostic. The only property the class has that helps treat warnings as errors conditionally is WarnOrErrorOnTargetArchitectureMismatch, not what you are trying to achieve. You can have a look-see for yourself with a decompiler, look at C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Build.Tasks.v12.0.dll. The resource name for the localized MSB3277 message is "ResolveAssemblyReference.FoundConflicts".

So only way to get ahead here is to write a little utility that parses the log file and looks for the warning.

Другие советы

You can use the generic mechanism MSBuildTreatWarningsAsErrors or <MSBuildWarningsAsErrors>MSB3277</MSBuildWarningsAsErrors> (introduced in #1928) to accomplish this.

Run Update-Package via Package Manager Console, this will fix MSB3277, what it does it reinstall all the packages and all related assemblies they come with to the highest version possible.

More info on official docs https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages

It looks like the /warnaserror will promote all msbuild warnings to errors:

TreatWarningsAsErrors vs /warnaserror

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top