Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,5 +57,34 @@ internal static bool IsMonoAndroidFramework(NuGetFramework framework)
framework.Framework,
FrameworkConstants.FrameworkIdentifiers.MonoAndroid);
}

/// <summary>
/// Determines whether selected MonoAndroid assets should produce a deprecation warning.
/// </summary>
/// <param name="compileAssetFramework">The framework selected for compile assets.</param>
/// <param name="compileTimeAssemblies">The selected compile assets.</param>
/// <param name="runtimeAssetFramework">The framework selected for runtime assets.</param>
/// <param name="runtimeAssemblies">The selected runtime assets.</param>
/// <returns>True when a package contributes non-placeholder MonoAndroid compile or runtime assets.</returns>
internal static bool ShouldWarn(
NuGetFramework compileAssetFramework,
IEnumerable<LockFileItem> compileTimeAssemblies,
NuGetFramework runtimeAssetFramework,
IEnumerable<LockFileItem> runtimeAssemblies)
{
return HasNonEmptyMonoAndroidAssets(compileAssetFramework, compileTimeAssemblies)
|| HasNonEmptyMonoAndroidAssets(runtimeAssetFramework, runtimeAssemblies);
}

private static bool HasNonEmptyMonoAndroidAssets(NuGetFramework framework, IEnumerable<LockFileItem> assets)
{
return IsMonoAndroidFramework(framework)
&& assets.Any(asset => !IsEmptyFolder(asset.Path));
}

private static bool IsEmptyFolder(string path)
{
return path.EndsWith(PackagingCoreConstants.ForwardSlashEmptyFolder, StringComparison.Ordinal);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down