[英]Dotnet build fails when project includes foreign language resources
我使用的是 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/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.