Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dotnet build fails when project includes foreign language resources

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?

like image 637
Eric Avatar asked Mar 22 '18 13:03

Eric


1 Answers

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/

like image 191
Stefan Steinegger Avatar answered Oct 17 '22 03:10

Stefan Steinegger