我使用的是 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.
我可以提供重现此错误的步骤:
DotNetBugTest
. 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
你得到错误。
有人知道如何解决这个问题吗?或者甚至建议去哪里看?
最佳答案
看来你必须使用MSBuild来构建这个项目。
另见这篇文章:
https://blog.codeinside.eu/2019/11/30/build-dotnetcore-apps-with-msbuild-to-avoid-strange-netframeworkbased-errors/
关于c# - 当项目包含外语资源时,Dotnet 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49430228/