Search code examples
c#gitlabcontinuous-integrationdotnetnuke

Gitlab CI fails because of compile warnings


I created a CI pipeline using Nuke that builds my project. On this stage the project throws some warnings that I'd like to ignore, but CI treats them as errors and fails. I want to suppress this behavior. How can I do that? Here is my log.

2:54:47 [INF] > /usr/bin/dotnet build Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj --configuration Release
12:54:47 [DBG] MSBuild version 17.9.8+b34f75857 for .NET
12:54:47 [DBG]   Determining projects to restore...
12:54:48 [DBG]   All projects are up-to-date for restore.
12:54:50 [DBG]   Hlc.Contracts.Core -> /builds/hlc/core/Contracts/Hlc.Contracts.Core/bin/Release/net6.0/Hlc.Contracts.Core.dll
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/Client/AsyncTcpClient.cs(34,40): error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(91,23): error CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(44,43): error CS8618: Non-nullable field '_handler' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(62,19): error CS8618: Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(63,23): error CS8618: Non-nullable property 'RemoteEndpoint' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(44,43): error CS0649: Field 'LlcTcpClient._handler' is never assigned to, and will always have its default value null [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(58,17): error CS0414: The field 'LlcTcpClient._reconnectionAttempts' is assigned but its value is never used [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [DBG] 
12:54:50 [DBG] Build FAILED.
12:54:50 [DBG] 
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/Client/AsyncTcpClient.cs(34,40): error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(91,23): error CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(44,43): error CS8618: Non-nullable field '_handler' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(62,19): error CS8618: Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(63,23): error CS8618: Non-nullable property 'RemoteEndpoint' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(44,43): error CS0649: Field 'LlcTcpClient._handler' is never assigned to, and will always have its default value null [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [ERR] /builds/hlc/core/Contracts/Hlc.Contracts.Tools/Tcp/LlcTcp/LlcTcpClientDev.cs(58,17): error CS0414: The field 'LlcTcpClient._reconnectionAttempts' is assigned but its value is never used [/builds/hlc/core/Contracts/Hlc.Contracts.Tools/Hlc.Contracts.Tools.csproj]
12:54:50 [DBG]     0 Warning(s)
12:54:50 [DBG]     7 Error(s)
12:54:50 [DBG] 
12:54:50 [DBG] Time Elapsed 00:00:03.38
12:54:50 [ERR] Target Compile has thrown an exception

Solution

  • You need to change <TreatWarningsAsErrors> tag in Directory.Build.props file to false and then everything will work. This error is specific for Nuke.