Muokkaa

Jaa


MSBuild custom derived build events deprecated

Custom derived build events of any subclass of BuildEventArgs by any build extensibility (mainly custom tasks) have been deprecated.

Previous behavior

Previously, you could derive from any subclass of BuildEventArgs and use those types freely in custom tasks and other build extensibility points.

New behavior

Starting in .NET 8, a build error is issued if your code uses any type derived from BuildEventArgs and you build using the .NET 8 version of MSBuild, that is, from the command line:

Usage of unsecure BinaryFormatter during serialization of custom event type 'MyCustomBuildEventArgs'. This will be deprecated soon. Please use Extended*EventArgs instead. More info: https://aka.ms/msbuild/eventargs

Starting from Visual Studio version 17.10, the same behavior applies to builds in Visual Studio.

Version introduced

.NET 8 RC 1

Type of change

This change is a behavioral change.

Reason for change

BinaryFormatter serialization is obsolete in .NET 8 and later versions. Any use of BinaryFormatter is deamed unsecure and throws an exception at run time. Since MSBuild custom derived build events use BinaryFormatter, your build would crash if you use these events in your build. The new build error provides a more graceful failure.

Use one of the following newly introduced, built-in events for extensibility instead of your custom derived build event:

Alternatively, you can temporarily disable the check by explicitly setting the environment variable MSBUILDCUSTOMBUILDEVENTWARNING to something other than 1.

Affected APIs