From 9ba03a27a58116adf7d8d02b46c3f7047500afed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 02:47:37 +0000 Subject: [PATCH 1/3] Initial plan From 1f910a22f6dbd018d79b52e32e07a2d9aa173bc6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 03:16:05 +0000 Subject: [PATCH 2/3] Add NETSDK1234 warning for macOS apps with .App or .Service suffix Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com> --- src/Tasks/Common/Resources/Strings.resx | 6 +- src/Tasks/Common/Resources/xlf/Strings.cs.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.de.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.es.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.fr.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.it.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ja.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ko.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.pl.xlf | 5 + .../Common/Resources/xlf/Strings.pt-BR.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.ru.xlf | 5 + src/Tasks/Common/Resources/xlf/Strings.tr.xlf | 5 + .../Common/Resources/xlf/Strings.zh-Hans.xlf | 5 + .../Common/Resources/xlf/Strings.zh-Hant.xlf | 5 + .../Microsoft.NET.MacOSAppName.targets | 36 ++++ .../Microsoft.NET.Sdk.BeforeCommon.targets | 3 + ...GivenThatWeWantToWarnAboutMacOSAppNames.cs | 170 ++++++++++++++++++ 17 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.MacOSAppName.targets create mode 100644 test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx index 518abb95d3de..6c4124100961 100644 --- a/src/Tasks/Common/Resources/Strings.resx +++ b/src/Tasks/Common/Resources/Strings.resx @@ -1010,5 +1010,9 @@ You may need to build the project on another operating system or architecture, o NETSDK1233: Targeting .NET 10.0 or higher in Visual Studio 2022 17.14 is not supported. {StrBegins="NETSDK1233: "} - + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + + diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf index b3150ec53b65..34b33b508f15 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: Knihovna JIT {0} se nenašla. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: Balíček Microsoft.Net.Sdk.Compilers.Toolset není stažen, ale je potřeba, protože verze MSBuild a SDK se neshodují. Ujistěte se, že verze {0} balíčku je dostupná ve zdrojových kanálech NuGet, a pak spusťte obnovení balíčku NuGet z Visual Studia nebo MSBuildu. diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf index 2d96be400f70..7d45ed895e1b 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: Die JIT-Bibliothek "{0}" wurde nicht gefunden. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: Das Paket Microsoft.Net.Sdk.Compilers.Toolset wurde nicht heruntergeladen, ist aber erforderlich, da ihre MSBuild- und SDK-Versionen nicht übereinstimmen. Stellen Sie sicher, dass Version {0} des Pakets in Ihren NuGet-Quellenfeeds verfügbar ist, und führen Sie dann die NuGet-Paketwiederherstellung von Visual Studio oder MSBuild aus. diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf index c809c4172947..81bb1acde92c 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: No se encontró la biblioteca JIT "{0}". {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: el paquete Microsoft.Net.Sdk.Compilers.Toolset no se ha descargado, pero es necesario porque las versiones de MSBuild y SDK no coinciden. Asegúrese de que la versión {0} del paquete esté disponible en las fuentes de origen de NuGet y, a continuación, ejecute la restauración del paquete NuGet desde Visual Studio o MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf index 4f8f47200d1c..fbdac9371c52 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: la bibliothèque JIT '{0}' est introuvable. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: le package Microsoft.Net.Sdk.Compilers.Toolset n’est pas téléchargé, mais il est nécessaire, car vos versions MSBuild et SDK ne correspondent pas. Vérifiez que la version {0} du package est disponible dans vos flux sources NuGet, puis exécutez la restauration du package NuGet à partir de Visual Studio ou MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf index 6f47775c6a67..d703dc7d1b98 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: la libreria '{0}' di JIT non è stata trovata. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: il pacchetto Microsoft.Net.Sdk.Compilers.Toolset non è scaricato, ma è necessario perché le versioni di MSBuild e SDK non corrispondono. Verificare che la versione {0} del pacchetto sia disponibile nei feed di origine NuGet e quindi eseguire il ripristino del pacchetto NuGet da Visual Studio o MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf index 03fb4261129c..7da97b2bdc27 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: JIT ライブラリ '{0}' が見つかりません。 {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: パッケージ Microsoft.Net.Sdk.Compilers.Toolset がダウンロードされていませんが、MSBuild と SDK のバージョンが一致していないため、このパッケージが必要です。NuGet ソース フィードでパッケージのバージョン {0} が使用できることを確認してから、Visual Studio または MSBuild から NuGet パッケージの復元を実行します。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf index 367083c96234..4100bc3c0556 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: JIT 라이브러리 '{0}'을(를) 찾을 수 없습니다. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: 패키지 Microsoft.Net.Sdk.Compilers.Toolset이 다운로드되지 않았지만 MSBuild 및 SDK 버전이 일치하지 않기 때문에 필요합니다. NuGet 소스 피드에서 패키지의 {0} 버전을 사용할 수 있는지 확인한 다음 Visual Studio 또는 MSBuild에서 NuGet 패키지 복원을 실행합니다. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf index 9ae273652d32..b5a0f135becf 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: nie znaleziono biblioteki JIT "{0}". {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: pakiet Microsoft.Net.Sdk.Compilers.Toolset nie został pobrany, ale jest potrzebny, ponieważ wersje programu MSBuild i zestawu SDK są niezgodne. Upewnij się, że wersja {0} pakietu jest dostępna w źródłach danych NuGet, a następnie uruchom przywracanie pakietu NuGet z programu Visual Studio lub MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf index e5dd12698ed0..98f79d173680 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: biblioteca JIT '{0}' não encontrada. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: o pacote Microsoft.Net.Sdk.Compilers.Toolset não foi baixado, mas é necessário porque suas versões do MSBuild e do SDK não são correspondentes. Verifique se a versão {0} do pacote está disponível nos feeds de origem do NuGet e execute a restauração do pacote NuGet do Visual Studio ou do MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf index 80990c05eb42..238c288bcd20 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: библиотека JIT "{0}" не найдена. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: пакет Microsoft.Net.Sdk.Compilers.Toolset не скачан, но он необходим из-за несоответствия версий MSBuild и SDK. Убедитесь, что версия {0} пакета доступна в исходных веб-каналах NuGet, а затем запустите восстановление пакета NuGet из Visual Studio или MSBuild. diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf index 3d5a18e84483..49231fb9f603 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: JIT kitaplığı '{0}' bulunamadı. {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: Microsoft.Net.Sdk.Compilers.Toolset paketi indirilmedi, ancak MSBuild ve SDK sürümleriniz eşleşmediğinden bu paket gereklidir. Paketin {0} sürümünün NuGet kaynak akışlarınız içinde kullanılabilir olduğundan emin olun ve ardından NuGet paketi geri yüklemesini Visual Studio veya MSBuild'den çalıştırın. diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf index 4724120c66ed..05ffb155f1c4 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: 找不到 JIT 库“{0}”。 {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: 包 Microsoft.Net.Sdk.Compilers.Toolset 不可下载,但由于你的 MSBuild 和 SDK 版本不匹配,因此需要此包。确保包的版本 {0} 在你的 NuGet 源中可用,然后从 Visual Studio 或 MSBuild 运行 NuGet 包还原。 diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf index 9d8d0bf09817..69a4c55c54f3 100644 --- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf @@ -603,6 +603,11 @@ The following are names of parameters or literal values and should not be transl NETSDK1157: 找不到 JIT 程式庫 '{0}'。 {StrBegins="NETSDK1157: "} + + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + NETSDK1234: The application name '{0}' ends with '{1}' which may prevent the application from running on macOS. Rename the application or set the AssemblyName property to a different value. + {StrBegins="NETSDK1234: "} + NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild. NETSDK1216: Microsoft.Net.Sdk.Compilers.Toolset 未下載,但需要它,因為您的 MSBuild 和 SDK 版本不符。確保 NuGet 來源摘要中提供套件版本 {0},然後從 Visual Studio 或 MSBuild 執行 NuGet 套件還原。 diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.MacOSAppName.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.MacOSAppName.targets new file mode 100644 index 000000000000..14ea660c0138 --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.MacOSAppName.targets @@ -0,0 +1,36 @@ + + + + + true + + + + + + <_InvalidMacOSAppNameSuffix Condition="$(AssemblyName.EndsWith('.App'))">.App + <_InvalidMacOSAppNameSuffix Condition="$(AssemblyName.EndsWith('.Service'))">.Service + + + + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index ce9388ef9976..313fc00df167 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -87,6 +87,9 @@ Copyright (c) .NET Foundation. All rights reserved. + + + <_IsNETCoreOrNETStandard Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">true diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs new file mode 100644 index 000000000000..bb9645612cb6 --- /dev/null +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs @@ -0,0 +1,170 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.NET.Build.Tasks; + +namespace Microsoft.NET.Build.Tests +{ +#pragma warning disable CS8602 // Dereference of a possibly null reference + public class GivenThatWeWantToWarnAboutMacOSAppNames : SdkTest + { + public GivenThatWeWantToWarnAboutMacOSAppNames(ITestOutputHelper log) : base(log) + { + } + + [Fact] + public void It_warns_when_app_name_ends_with_App_on_macOS() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.App")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-x64") + .Should() + .Pass() + .And.HaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_warns_when_app_name_ends_with_Service_on_macOS() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.Service")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-arm64") + .Should() + .Pass() + .And.HaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_does_not_warn_when_app_name_does_not_end_with_App_or_Service() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTestApplication")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-x64") + .Should() + .Pass() + .And.NotHaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_does_not_warn_when_not_targeting_macOS() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.App")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=win-x64") + .Should() + .Pass() + .And.NotHaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_can_be_suppressed_with_CheckMacOSAppName_property() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.App")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-x64", "/p:CheckMacOSAppName=false") + .Should() + .Pass() + .And.NotHaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_can_be_suppressed_with_NoWarn() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.App")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-x64", "/p:NoWarn=NETSDK1234") + .Should() + .Pass() + .And.NotHaveStdOutContaining("NETSDK1234"); + } + + [Fact] + public void It_does_not_warn_for_library_projects() + { + TestAsset testAsset = _testAssetsManager + .CopyTestAsset("HelloWorld") + .WithSource() + .WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace!; + var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First(); + propertyGroup.Add(new XElement(ns + "AssemblyName", "MyTest.App")); + propertyGroup.Add(new XElement(ns + "OutputType", "Library")); + }); + + var buildCommand = new BuildCommand(testAsset); + + buildCommand + .Execute("/p:RuntimeIdentifier=osx-x64") + .Should() + .Pass() + .And.NotHaveStdOutContaining("NETSDK1234"); + } + } +} From d2fd9ca6f731807b3910d24c6dfd0d403fd8426c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Oct 2025 18:13:35 +0000 Subject: [PATCH 3/3] Add --verbosity:minimal to NoWarn test to prevent false positive Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com> --- .../GivenThatWeWantToWarnAboutMacOSAppNames.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs index bb9645612cb6..590728188707 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToWarnAboutMacOSAppNames.cs @@ -138,7 +138,7 @@ public void It_can_be_suppressed_with_NoWarn() var buildCommand = new BuildCommand(testAsset); buildCommand - .Execute("/p:RuntimeIdentifier=osx-x64", "/p:NoWarn=NETSDK1234") + .Execute("/p:RuntimeIdentifier=osx-x64", "/p:NoWarn=NETSDK1234", "--verbosity:minimal") .Should() .Pass() .And.NotHaveStdOutContaining("NETSDK1234");