当项目包含外语资源时,Dotnet构建失败。

问题描述 投票:13回答:1

我使用的是Visual Studio 15.6.3,dotnet SDK 2.1.102。

最近,(也许是在更新之后)我追踪到了一个dotnet构建错误,这个错误显示在一个包含外语资源的项目上。错误信息如下。

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.

我可以提供重现这个错误的步骤。

  1. 在Visual Studio中创建一个C#控制台应用程序,调用它: DotNetBugTest.
  2. 编辑项目属性,在构建下,取消勾选 "首选32位" (控制台应用程序构件).
  3. 在项目的根级添加一个资源,将其称为 Messages.resx.
  4. 添加一个字符串资源,调用它 A,并给它配上文字 English.
  5. 在项目的根级添加另一个资源,将其称为 Messages.fr-CA.resx.
  6. 添加相同的字符串资源,调用它 A,并给它配上文字 French.
  7. 现在在 Program 类,添加以下内容。

    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();
        }
    }
    

这在Visual Studio中运行良好 输出。

en=English
fr=French

但如果你试图从命令行编译它..:

dotnet build --configuration Debug

你会得到错误信息

有人知道如何解决这个问题吗?甚至建议去哪里找?

c# .net build resources target-sdk
1个回答
0
投票

看来,你必须使用MSBuild来构建这个项目。

也请看这篇文章。https:/blog.codeinside.eu20191130build-dotnetcore-apps-with-msbuild-to-avoid-strange-netframework-based-errors。

© www.soinside.com 2019 - 2024. All rights reserved.