Closed KirillOsenkov closed 3 years ago
This was intermittent and happened only once.
https://github.com/dotnet/roslyn/issues/46772 is potentially related or same issue.
I'm running into this issues on MacOs Big Sur when using Project Tye to run a Blazor project. The other projects in the solution (one webapi and one console) build fine. This also only started happening when I upgraded my project to .NET 5
Same on big sur with a .NET Core console application. :(
I'm having the same issues, on Windows 10, and still no solution so far.
The "Csc" task failed unexpectedly.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: System.InvalidOperationException: The "Csc" task has not registered its resources. In order to use the "TaskLoggingHelper.FormatResourceString()" method this task needs to register its resources either during construction, or via the "TaskResources" property.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Team Triage: @KirillOsenkov We're wondering how/where this would be an issue with MSBuild. At first glance this looks like an issue with Roslyn as it's in a targets file under Roslyn\
and has to do with the csc
task.
@jaredpar we think there's an intermittent issue with the Csc task, any quick guesses? Have you seen this before?
As far as I can tell, this is where Csc initializes its resources, which is pretty early on, in the constructor of the base class: https://github.com/dotnet/roslyn/blob/275f4c790945c73ca308716ba56c224a95e13ca9/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs#L59
Should it be calling this constructor instead? https://github.com/dotnet/msbuild/blob/38da84d453b14008b148c7eea28df24ab4443bb7/src/Utilities/ToolTask.cs#L91
Never seen this before nor do I know what is required. Just based off the info here I suspect we're running into the following line
https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs#L557
At the same time I'm not sure what is missing that we should be doing.
Yup, you're right, it looks like there's an exception on that line (we don't know which one), and when trying to log it, we fail to get the resource string because resources haven't been initialized.
Yeah you need to register resources via the constructor or the TaskResources property
I've filed Roslyn issue https://github.com/dotnet/roslyn/issues/52467 - would be nice to fix this soon, as a lot of customers are hitting this
Yeah you need to register resources via the constructor or the TaskResources property
Turn out this isn't 100% true. The problem is that we're going through TaskLoggingHelper
. Even though that takes an ITask
as a constructor argument it does not utilize the ITask.TaskResources
property. Instead you have to manually set that up on TaskLoggingHelper
instances.
So even though our Task
registered everything properly the TaskLoggingHelper
didn't take advantage of it. That's a bit unintuitive.
Yeah I think I saw you're creating an isolated TaskLoggingHelper
that's disconnected from the task, and one probably needs to pass stuff to it for it to work as expected. Unfortunately this silly exception is hiding the real exception that's happening in the compiler server.
Yep. Thats' what I get for trying to use the right API for logging exceptions š¦
Fix is easy but testing requires me to restructure the code a bit.
Team Triage: Closing since the fix is available within roslyn. @jaredpar if you think there's anything we can do in our API to make this easier, let us know.
Team Triage: Closing since the fix is available within roslyn. @jaredpar if you think there's anything we can do in our API to make this easier, let us know.
IMHO, you should really consider one of two bug fixes here:
TaskLoggingHelper
to initialize TaskResources
based on the ITask
in the constructor TaskLoggingHelper.TaskResources
to fall back to ITask.TaskResources
if the value is null
This seems relatively safe because in the cases where this has an impact the code would already be in a failure state. I imagine I'm not the only one who making the assumption that a type named TaskLoggingHelper
would attempt to get critical state from the provided ITask
.
Sorry, accidentally button slip and hit re-open.
Change TaskLoggingHelper.TaskResources to fall back to ITask.TaskResources if the value is null
Sounds to me like a reasonable ask, Reopening for triage
BLARG you also need to manually set IBuildEngine
in the TaskLoggingHelper
.
At this point I think the fastest way to fix this bug is to stop using TaskLoggingHelper
. It's just causing pain at this point because the usability level is not good. Really think you all should add constructors that actually take the arguments necessary to make type functional and deprecate the existing ones. Current state is just leading users to this type of bug.
@BenVillalobos in dotnet/runtime we've gotten random build failures with this callstack. +1 to some fix this iteration.
This was fixed in https://github.com/dotnet/roslyn/pull/52836. Newer versions of the SDK should have the fix and give the correct stack traces.
Hi @jaredpar I was wondering what is it that I need to update in order to get the fix? I am a little lost. I have upgraded my SDK to the latest version (released June 8 2021, v 5.0.301 ) but I still see this error when trying to build my NET 5 WebApi project in my Mac Big Sur
@dglozano
My expectation is that this would be included in 5.0.301 as that change went into VS 16.10. Can you grab a bin log of the build there and share that out? Want to make sure it's using the expected compiler vs. getting one pushed in via a package.
Note: since this bug was closed we did see the failures start to popup in our repos. This is the most likely candidate at the moment https://github.com/dotnet/runtime/issues/53420
Hi @jaredpar here is what I could get. I have never generated a binlog before. I was expecting a file to be generated, but I can't find one in the path I specified... so I am just attaching the console output.
Not sure if it's this what you need. Let me know if there is anything else I could get for you.
dotnet build -bl:~/Logs/msbuild.binlog 1 āµ dglozano@DGLOZANO
Microsoft (R) Build Engine version 16.10.1+2fd48ab73 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/local/share/dotnet/sdk/5.0.301/MSBuild.dll -bl:~/Logs/msbuild.binlog -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/local/share/dotnet/sdk/5.0.301/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/local/share/dotnet/sdk/5.0.301/dotnet.dll -maxcpucount -restore -verbosity:m ./Altus.DI.UI.Web.Net5.csproj
Determining projects to restore...
All projects are up-to-date for restore.
Altus.DI.Core -> /Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.Core/bin/Debug/netstandard2.0/Altus.DI.Core.dll
Altus.DI.Shared -> /Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.Shared/bin/Debug/netstandard2.0/Altus.DI.Shared.dll
Altus.DI.Repository -> /Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.Repository/bin/Debug/netstandard2.0/Altus.DI.Repository.dll
Altus.DI.Proxy -> /Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.Proxy/bin/Debug/netstandard2.0/Altus.DI.Proxy.dll
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: The "Csc" task failed unexpectedly. [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: System.InvalidOperationException: The "Csc" task has not registered its resources. In order to use the "TaskLoggingHelper.FormatResourceString()" method this task needs to register its resources either during construction, or via the "TaskResources" property. [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute() [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
Build FAILED.
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: The "Csc" task failed unexpectedly. [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: System.InvalidOperationException: The "Csc" task has not registered its resources. In order to use the "TaskLoggingHelper.FormatResourceString()" method this task needs to register its resources either during construction, or via the "TaskResources" property. [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute() [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
/Users/dglozano/.nuget/packages/microsoft.net.compilers/3.9.0/tools/Microsoft.CSharp.Core.targets(71,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/Users/dglozano/Projects/digital-well-intervention/src/Altus.DI.UI.Web.Net5/Altus.DI.UI.Web.Net5.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.32
And the output of dotnet --info
just in case.
.NET SDK (reflecting any global.json):
Version: 5.0.301
Commit: ef17233f86
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.0
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /usr/local/share/dotnet/sdk/5.0.301/
Host (useful for support):
Version: 5.0.7
Commit: 556582d964
.NET SDKs installed:
3.1.302 [/usr/local/share/dotnet/sdk]
3.1.409 [/usr/local/share/dotnet/sdk]
5.0.203 [/usr/local/share/dotnet/sdk]
5.0.300 [/usr/local/share/dotnet/sdk]
5.0.301 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
@dglozano thanks that confirmed my suspicions
Your project / solution has an installation of Microsoft.Net.Compilers that is overriding the C# compiler that comes from the SDK. Removing that will let you use the C# compiler that comes with the SDK that should have this fix.
Note: in general that package is not supported for long term usage of this sort. It is meant as a mechanism for shipping short term patches to customers only.
Thanks @jaredpar ! Can confirm that removing the nuget package fixed the issue š
I got the same problem. And it is very interesting that when I run Visual Studio as administrator, I was able to get build without any problem.
@cihancoskun at this point it's better to open a new issue with any other info. I would also try repairing your installs since maybe a file has the wrong ACL? (not sure whether repair fixes ACLS)
I have got the same issue and tried to rebuild and my Jenkins jobs completed successfully, looks like this is an intermittent issue
Building using bootstrap MSBuild from 80b7f2dcb has resulted in a Csc failure: