diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
index 80572729569..2af263f55da 100644
--- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
+++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
@@ -288,8 +288,11 @@ public LockFile CreateLockFile(LockFile previousLockFile,
// Log NU1703 warning if the package uses the deprecated MonoAndroid framework
if (checkMonoAndroidDeprecation
&& !librariesWithMonoAndroidWarnings.Contains(library)
- && (MonoAndroidDeprecation.IsMonoAndroidFramework(compileAssetFramework)
- || MonoAndroidDeprecation.IsMonoAndroidFramework(runtimeAssetFramework)))
+ && MonoAndroidDeprecation.ShouldWarn(
+ compileAssetFramework,
+ targetLibrary.CompileTimeAssemblies,
+ runtimeAssetFramework,
+ targetLibrary.RuntimeAssemblies))
{
var message = string.Format(CultureInfo.CurrentCulture,
Strings.Warning_MonoAndroidFrameworkDeprecated,
diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/MonoAndroidDeprecation.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/MonoAndroidDeprecation.cs
index 4bbd0b0a61c..22d0ae2bf3d 100644
--- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/MonoAndroidDeprecation.cs
+++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/MonoAndroidDeprecation.cs
@@ -2,7 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Collections.Generic;
+using System.Linq;
using NuGet.Frameworks;
+using NuGet.Packaging.Core;
using NuGet.ProjectModel;
namespace NuGet.Commands
@@ -54,5 +57,34 @@ internal static bool IsMonoAndroidFramework(NuGetFramework framework)
framework.Framework,
FrameworkConstants.FrameworkIdentifiers.MonoAndroid);
}
+
+ ///
+ /// Determines whether selected MonoAndroid assets should produce a deprecation warning.
+ ///
+ /// The framework selected for compile assets.
+ /// The selected compile assets.
+ /// The framework selected for runtime assets.
+ /// The selected runtime assets.
+ /// True when a package contributes non-placeholder MonoAndroid compile or runtime assets.
+ internal static bool ShouldWarn(
+ NuGetFramework compileAssetFramework,
+ IEnumerable compileTimeAssemblies,
+ NuGetFramework runtimeAssetFramework,
+ IEnumerable runtimeAssemblies)
+ {
+ return HasNonEmptyMonoAndroidAssets(compileAssetFramework, compileTimeAssemblies)
+ || HasNonEmptyMonoAndroidAssets(runtimeAssetFramework, runtimeAssemblies);
+ }
+
+ private static bool HasNonEmptyMonoAndroidAssets(NuGetFramework framework, IEnumerable assets)
+ {
+ return IsMonoAndroidFramework(framework)
+ && assets.Any(asset => !IsEmptyFolder(asset.Path));
+ }
+
+ private static bool IsEmptyFolder(string path)
+ {
+ return path.EndsWith(PackagingCoreConstants.ForwardSlashEmptyFolder, StringComparison.Ordinal);
+ }
}
}
diff --git a/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/MonoAndroidDeprecationTests.cs b/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/MonoAndroidDeprecationTests.cs
index aea50ceabbf..e2d4041a643 100644
--- a/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/MonoAndroidDeprecationTests.cs
+++ b/test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/MonoAndroidDeprecationTests.cs
@@ -119,6 +119,30 @@ public void IsMonoAndroidFramework_Null_ReturnsFalse()
#endregion
+ #region ShouldWarn tests
+
+ [Fact]
+ public void ShouldWarn_MonoAndroidWithOnlyEmptyFolderPlaceholders_ReturnsFalse()
+ {
+ var monoAndroid = NuGetFramework.Parse("monoandroid10.0");
+ var compileItems = new[]
+ {
+ new LockFileItem("ref/MonoAndroid10/_._")
+ };
+ var runtimeItems = new[]
+ {
+ new LockFileItem("lib/MonoAndroid10/_._")
+ };
+
+ MonoAndroidDeprecation.ShouldWarn(
+ monoAndroid,
+ compileItems,
+ monoAndroid,
+ runtimeItems).Should().BeFalse();
+ }
+
+ #endregion
+
#region Integration tests
[Fact]