簡體   English   中英

當項目包含外語資源時,Dotnet 構建失敗

[英]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.

我可以提供重現此錯誤的步驟:

  1. 在 Visual Studio 中創建一個 C# 控制台應用程序,將其DotNetBugTest
  2. 編輯項目屬性,在構建下,取消選中“Prefer 32-bit”(控制台應用程序工件)。
  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

你得到錯誤。

有人知道如何解決這個問題嗎? 或者甚至建議去哪里看?

看來你必須使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM