diff --git a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
index 2b6b6e8268f..a1cb1da4e3c 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
+++ b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
@@ -939,6 +939,7 @@ Copyright (c) .NET Foundation. All rights reserved.
$(TargetFrameworkIdentifier)
$(TargetFrameworkVersion)
$(TargetFrameworkMoniker)
+ $(TargetFrameworkProfile)
$(TargetPlatformIdentifier)
$(TargetPlatformVersion)
$(TargetPlatformMinVersion)
diff --git a/src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Unshipped.txt b/src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Unshipped.txt
index e69de29bb2d..41651d04ab5 100644
--- a/src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Unshipped.txt
+++ b/src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Unshipped.txt
@@ -0,0 +1 @@
+static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetFrameworkIdentifier, string targetFrameworkVersion, string targetFrameworkProfile, string targetPlatformIdentifier, string targetPlatformVersion, string targetPlatformMinVersion) -> NuGet.Frameworks.NuGetFramework
\ No newline at end of file
diff --git a/src/NuGet.Core/NuGet.Commands/PublicAPI/netcoreapp5.0/PublicAPI.Unshipped.txt b/src/NuGet.Core/NuGet.Commands/PublicAPI/netcoreapp5.0/PublicAPI.Unshipped.txt
index e69de29bb2d..41651d04ab5 100644
--- a/src/NuGet.Core/NuGet.Commands/PublicAPI/netcoreapp5.0/PublicAPI.Unshipped.txt
+++ b/src/NuGet.Core/NuGet.Commands/PublicAPI/netcoreapp5.0/PublicAPI.Unshipped.txt
@@ -0,0 +1 @@
+static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetFrameworkIdentifier, string targetFrameworkVersion, string targetFrameworkProfile, string targetPlatformIdentifier, string targetPlatformVersion, string targetPlatformMinVersion) -> NuGet.Frameworks.NuGetFramework
\ No newline at end of file
diff --git a/src/NuGet.Core/NuGet.Commands/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/src/NuGet.Core/NuGet.Commands/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
index e69de29bb2d..41651d04ab5 100644
--- a/src/NuGet.Core/NuGet.Commands/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
+++ b/src/NuGet.Core/NuGet.Commands/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
@@ -0,0 +1 @@
+static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetFrameworkIdentifier, string targetFrameworkVersion, string targetFrameworkProfile, string targetPlatformIdentifier, string targetPlatformVersion, string targetPlatformMinVersion) -> NuGet.Frameworks.NuGetFramework
\ No newline at end of file
diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs
index 23ac451493c..0e757cf7948 100644
--- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs
+++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs
@@ -426,6 +426,7 @@ private static IEnumerable GetTargetFrameworkInforma
var targetFrameworkIdentifier = item.GetProperty("TargetFrameworkIdentifier");
var targetFrameworkVersion = item.GetProperty("TargetFrameworkVersion");
var targetFrameworkMoniker = item.GetProperty("TargetFrameworkMoniker");
+ var targetFrameworkProfile = item.GetProperty("TargetFrameworkProfile");
var targetPlatformIdentifier = item.GetProperty("TargetPlatformIdentifier");
var targetPlatformVersion = item.GetProperty("TargetPlatformVersion");
var targetPlatformMinVersion = item.GetProperty("TargetPlatformMinVersion");
@@ -437,18 +438,19 @@ private static IEnumerable GetTargetFrameworkInforma
}
uniqueIds.Add(targetAlias);
- IEnumerable targetFramework = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
- projectFilePath: filePath,
- targetFrameworks: null,
- targetFramework: null,
- targetFrameworkMoniker: targetFrameworkMoniker,
- targetPlatformIdentifier: targetPlatformIdentifier,
- targetPlatformVersion: targetPlatformVersion,
- targetPlatformMinVersion: targetPlatformMinVersion);
+ NuGetFramework targetFramework = MSBuildProjectFrameworkUtility.GetProjectFramework(
+ projectFilePath: filePath,
+ targetFrameworkMoniker: targetFrameworkMoniker,
+ targetFrameworkIdentifier: targetFrameworkIdentifier,
+ targetFrameworkVersion: targetFrameworkVersion,
+ targetFrameworkProfile: targetFrameworkProfile,
+ targetPlatformIdentifier: targetPlatformIdentifier,
+ targetPlatformVersion: targetPlatformVersion,
+ targetPlatformMinVersion: targetPlatformMinVersion);
var targetFrameworkInfo = new TargetFrameworkInformation()
{
- FrameworkName = NuGetFramework.Parse(targetFramework.Single()),
+ FrameworkName = targetFramework,
TargetAlias = targetAlias
};
if (restoreType == ProjectStyle.PackageReference)
diff --git a/src/NuGet.Core/NuGet.Commands/Utility/MSBuildProjectFrameworkUtility.cs b/src/NuGet.Core/NuGet.Commands/Utility/MSBuildProjectFrameworkUtility.cs
index b3f459ba2b2..4a3d2d29964 100644
--- a/src/NuGet.Core/NuGet.Commands/Utility/MSBuildProjectFrameworkUtility.cs
+++ b/src/NuGet.Core/NuGet.Commands/Utility/MSBuildProjectFrameworkUtility.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using NuGet.Common;
using NuGet.Frameworks;
@@ -34,6 +35,36 @@ public static IEnumerable GetProjectFrameworkStrings(
isXnaWindowsPhoneProject: false);
}
+ ///
+ /// Given the properties from an msbuild project file and a the file path, infer the target framework.
+ /// This method prioritizes projects without a framework, such as vcxproj and accounts for the mismatching arguments in UAP projects, where the TFI and TFV are set but should be ignored.
+ /// Likewise, this method will *ignore* unnecessary properties, such as TPI and TPV when profiles are used, and frameworks that do not support platforms have some default values.
+ ///
+ /// The inferred framework. Unsupported otherwise.
+ public static NuGetFramework GetProjectFramework(
+ string projectFilePath,
+ string targetFrameworkMoniker,
+ string targetFrameworkIdentifier,
+ string targetFrameworkVersion,
+ string targetFrameworkProfile,
+ string targetPlatformIdentifier,
+ string targetPlatformVersion,
+ string targetPlatformMinVersion)
+ {
+ return GetProjectFramework(
+ projectFilePath,
+ targetFrameworkMoniker,
+ targetFrameworkIdentifier,
+ targetFrameworkVersion,
+ targetFrameworkProfile,
+ targetPlatformIdentifier,
+ targetPlatformVersion,
+ targetPlatformMinVersion,
+ isXnaWindowsPhoneProject: false,
+ isManagementPackProject: false,
+ GetAsNuGetFramework);
+ }
+
///
/// Determine the target framework of an msbuild project.
///
@@ -47,6 +78,37 @@ public static IEnumerable GetProjectFrameworkStrings(
string targetPlatformMinVersion,
bool isXnaWindowsPhoneProject,
bool isManagementPackProject)
+ {
+ return GetProjectFrameworks(
+ projectFilePath,
+ targetFrameworks,
+ targetFramework,
+ targetFrameworkMoniker,
+ targetFrameworkIdentifier: null,
+ targetFrameworkVersion: null,
+ targetFrameworkProfile: null,
+ targetPlatformIdentifier,
+ targetPlatformVersion,
+ targetPlatformMinVersion,
+ isXnaWindowsPhoneProject,
+ isManagementPackProject,
+ GetAsFrameworkString);
+ }
+
+ internal static IEnumerable GetProjectFrameworks(
+ string projectFilePath,
+ string targetFrameworks,
+ string targetFramework,
+ string targetFrameworkMoniker,
+ string targetFrameworkIdentifier,
+ string targetFrameworkVersion,
+ string targetFrameworkProfile,
+ string targetPlatformIdentifier,
+ string targetPlatformVersion,
+ string targetPlatformMinVersion,
+ bool isXnaWindowsPhoneProject,
+ bool isManagementPackProject,
+ Func