【发布时间】:2018-08-31 23:36:11
【问题描述】:
我正在使用 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.
我可以提供重现此错误的步骤:
- 在 Visual Studio 中创建一个 C# 控制台应用,将其命名为
DotNetBugTest。 - 编辑项目属性,在构建下,取消选中“首选 32 位”(控制台应用程序工件)。
- 在项目的根级别添加资源,命名为
Messages.resx。 - 添加一个字符串资源,将其命名为
A,并为其指定文本English。 - 在项目的根级别添加另一个资源,命名为
Messages.fr-CA.resx。 - 添加相同的字符串资源,将其命名为
A,并将文本命名为French。 -
现在在
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
你得到了错误。
有人知道如何解决这个问题吗?甚至建议去哪里看?
【问题讨论】:
-
根据您的说法,听起来您的项目使用的是完整的 .NET Framework,而不是 .NET Core,因此您确实应该使用 MSbuild。 dotnet 不支持 msbuild 所做的一切。
-
仅供参考,我最近偶然发现了这个错误。有一个完全不相关的“警告”,似乎并没有阻止 MSBuild 的构建。我引用了一个较旧的 Newtonsoft.Json 包,我修复了它(然后删除了错误)。后来我被允许通过 dotnet CLI 构建
标签: c# .net build resources target-sdk