Dotnet build fails when project includes foreign language resources
Asked Answered
C

1

19

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?

Condillac answered 22/3, 2018 at 13:41 Comment(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.Fief
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 CLIBrumal
A
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/

Angevin answered 15/5, 2020 at 9:0 Comment(1)
Please do you have a sample? I had the bad luck to help a guys which are mixed netcore and netframework 4.5.Mabe

© 2022 - 2024 — McMap. All rights reserved.