18

I am using Visual Studio 15.6.3, dotnet SDK 2.1.102.

Recently, (maybe after an update) I tracked down a dotnet build bug that is showing up to a project that includes foreign language resources. The error message is as follows:

C:\Program Files\dotnet\sdk\2.1.102\Microsoft.Common.CurrentVersion.targets(3570,5): error MSB4062: The "Microsoft.Build.Tasks.AL" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

I can provide steps to reproduce this error:

  1. Create a C# console app in Visual Studio, call it DotNetBugTest.
  2. Edit project properties, under build, uncheck "Prefer 32-bit" (console app artifact).
  3. Add a resource at root level of project, call it Messages.resx.
  4. Add a string resource, call it A, and give it the text English.
  5. Add another resource at the root level of project, call it Messages.fr-CA.resx.
  6. Add same string resource, call it A, and give it the text French.
  7. Now in the Program class, add the following:

    class Program
    {
        static void Main(string[] args)
        {
            var rm = new ResourceManager("DotNetBugTest.Messages", typeof(Program).Assembly);
    
            var en = CultureInfo.CreateSpecificCulture("en-US"); 
            var fr = CultureInfo.CreateSpecificCulture("fr-CA"); 
    
            Console.WriteLine($@"en={rm.GetString("A", en)}");
            Console.WriteLine($@"fr={rm.GetString("A", fr)}");
    
            Console.ReadKey();
        }
    }
    

This runs fine in Visual Studio. Outputs:

en=English
fr=French

But if you try to compile it from the command line:

dotnet build --configuration Debug

You get the error.

Does anybody have an idea how to fix this? Or even suggestions of where to look?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Eric
  • 2,207
  • 2
  • 16
  • 16
  • 2
    Based on what you said, it sounds like your project uses the full .NET Framework, not .NET Core, so you should really be using MSbuild. dotnet does not support everything msbuild does. – Zeus82 Apr 20 '18 at 15:54
  • FYI, I stumbled upon this error recently. Had a completely unrelated "warning" which didn't seem to prevent MSBuild from building. I had a reference to an older Newtonsoft.Json package, which I fixed (then removed the error). I was later allowed to build via dotnet CLI – Brian Jan 02 '19 at 19:15

1 Answers1

2

It seems that you have to use MSBuild to build this project.

See also this article: https://blog.codeinside.eu/2019/11/30/build-dotnetcore-apps-with-msbuild-to-avoid-strange-netframeworkbased-errors/

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193