diff --git a/global.json b/global.json
index 3f0f8d1b3a14..e1ed7103bbe3 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "2.2.100-preview1-009263"
+ "version": "2.2.100-preview3-009413"
},
"msbuild-sdks": {
"RoslynTools.RepoToolset": "1.0.0-beta2-62912-01"
diff --git a/src/Tasks/Common/MessageBase.cs b/src/Tasks/Common/MessageBase.cs
index 4400899be603..d68a44fdf6ad 100644
--- a/src/Tasks/Common/MessageBase.cs
+++ b/src/Tasks/Common/MessageBase.cs
@@ -12,10 +12,14 @@ namespace Microsoft.NET.Build.Tasks
///
public abstract class MessageBase : TaskBase
{
+ ///
+ /// Formatted text for the message
+ ///
+ public string FormattedText { get; set; }
+
///
/// The name of the resource in Strings.resx that contains the desired error message.
///
- [Required]
public string ResourceName { get; set; }
///
@@ -31,17 +35,34 @@ internal MessageBase()
protected override void ExecuteCore()
{
- if (FormatArguments == null || FormatArguments.Length == 0)
+ string message = null;
+ if (string.IsNullOrEmpty(FormattedText) && string.IsNullOrEmpty(ResourceName))
+ {
+ throw new ArgumentException($"Either {nameof(FormattedText)} or {nameof(ResourceName)} must be specified.");
+ }
+ else if (!string.IsNullOrEmpty(FormattedText) && !string.IsNullOrEmpty(ResourceName))
{
- // We use a single-item array with one empty string in this case so that
- // it is possible to interpret FormatArguments="$(EmptyVariable)" as a request
- // to pass an empty string on to string.Format. Note if there are not placeholders
- // in the string, then the empty string arg will be ignored.
- FormatArguments = EmptyArguments;
+ throw new ArgumentException($"Only one of {nameof(FormattedText)} and {nameof(ResourceName)} can be specified.");
}
+ else if (!string.IsNullOrEmpty(ResourceName))
+ {
+ if (FormatArguments == null || FormatArguments.Length == 0)
+ {
+ // We use a single-item array with one empty string in this case so that
+ // it is possible to interpret FormatArguments="$(EmptyVariable)" as a request
+ // to pass an empty string on to string.Format. Note if there are not placeholders
+ // in the string, then the empty string arg will be ignored.
+ FormatArguments = EmptyArguments;
+ }
- string format = Strings.ResourceManager.GetString(ResourceName, Strings.Culture);
- string message = string.Format(CultureInfo.CurrentCulture, format, FormatArguments);
+ string format = Strings.ResourceManager.GetString(ResourceName, Strings.Culture);
+ message = string.Format(CultureInfo.CurrentCulture, format, FormatArguments);
+ }
+ else
+ {
+ message = FormattedText;
+ }
+
LogMessage(message);
}
diff --git a/src/Tasks/Common/MetadataKeys.cs b/src/Tasks/Common/MetadataKeys.cs
index 03f63bcde64d..32b05ceb492e 100644
--- a/src/Tasks/Common/MetadataKeys.cs
+++ b/src/Tasks/Common/MetadataKeys.cs
@@ -16,6 +16,7 @@ internal static class MetadataKeys
public const string PackageVersion = "PackageVersion";
public const string IsImplicitlyDefined = "IsImplicitlyDefined";
public const string IsTopLevelDependency = "IsTopLevelDependency";
+ public const string AllowExplicitVersion = "AllowExplicitVersion";
// Target Metadata
public const string RuntimeIdentifier = "RuntimeIdentifier";
@@ -81,8 +82,5 @@ internal static class MetadataKeys
// Resource assemblies
public const string Culture = "Culture";
public const string DestinationSubDirectory = "DestinationSubDirectory";
-
- // Expected platform packages
- public const string ExpectedVersion = "ExpectedVersion";
}
}
diff --git a/src/Tasks/Common/Resources/Strings.resx b/src/Tasks/Common/Resources/Strings.resx
index 5c224b778060..780be934c921 100644
--- a/src/Tasks/Common/Resources/Strings.resx
+++ b/src/Tasks/Common/Resources/Strings.resx
@@ -401,4 +401,7 @@ The following are names of parameters or literal values and should not be transl
NETSDK1070: The application configuration file must have root configuration element.{StrBegin="NETSDK1070: "}
-
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+
\ No newline at end of file
diff --git a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
index caa3c1892517..9fcbb4b03aab 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.cs.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Chybí metadata {0} o {1} položky {2}.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Nerozpoznaný token preprocesoru {0} v {1}.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.de.xlf b/src/Tasks/Common/Resources/xlf/Strings.de.xlf
index 27cf73b474d7..9f1d2c98bef7 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.de.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.de.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Die Metadaten "{0}" für das Element "{2}" vom Typ "{1}" sind nicht vorhanden.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Unbekanntes Präprozessortoken "{0}" in "{1}".
diff --git a/src/Tasks/Common/Resources/xlf/Strings.es.xlf b/src/Tasks/Common/Resources/xlf/Strings.es.xlf
index 93f1f3acafc4..bbf74f031892 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.es.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.es.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Faltan los metadatos de "{0}" en el elemento de "{1}" "{2}".{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Token de preprocesador no reconocido "{0}" en "{1}".
diff --git a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
index a209ffc3c170..3de69b9fb9ef 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.fr.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Métadonnées '{0}' manquantes sur l'élément '{1}' '{2}'.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Jeton de préprocesseur '{0}' non reconnu dans '{1}'.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.it.xlf b/src/Tasks/Common/Resources/xlf/Strings.it.xlf
index c5326b87bd1f..756318f95e89 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.it.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.it.xlf
@@ -67,6 +67,11 @@
NETSDK1008: mancano i metadati di '{0}' sull'elemento '{2}' di '{1}'.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: token di preprocessore '{0}' non riconosciuto in '{1}'.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
index 803f87f04baf..bcd063d955e2 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ja.xlf
@@ -67,6 +67,11 @@
NETSDK1008: '{1}' 項目 '{2}' の '{0}' メタデータがありません。{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: 認識されないプリプロセッサ トークン '{0}' が '{1}' に存在します。
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
index 1a077a4df692..4bd049d808d1 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ko.xlf
@@ -67,6 +67,11 @@
NETSDK1008: '{1}' 항목 '{2}'에 '{0}' 메타데이터가 없습니다.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: '{1}'에서 전처리기 토큰 '{0}'을(를) 인식할 수 없습니다.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
index c62da27f1892..fe44886093f5 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.pl.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Brak metadanych „{0}” w elemencie „{1}” „{2}”.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Nierozpoznany token preprocesora „{0}” w elemencie „{1}”.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
index 8e4fbdc4ce16..81317289abc0 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
@@ -67,6 +67,11 @@
NETSDK1008: Metadados '{0}' ausentes no item '{1}' '{2}'.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: Token de pré-processador não reconhecido '{0}' em '{1}'.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
index 4527cffc23b6..bf871d2a21df 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.ru.xlf
@@ -67,6 +67,11 @@
NETSDK1008: отсутствуют метаданные "{0}" для элемента "{2}" в "{1}".{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: не распознан маркер препроцессора "{0}" в "{1}".
diff --git a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
index 1d90b1f8dbde..7eb3edd73d1a 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.tr.xlf
@@ -67,6 +67,11 @@
NETSDK1008: '{1}' öğesi '{2}' üzerinde '{0}' meta verileri eksik.{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: '{1}' içinde tanınmayan '{0}' ön işlemci belirteci.
diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
index 8a6cdb6454bc..a6359e9eb023 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
@@ -67,6 +67,11 @@
NETSDK1008: 在“{1}”项“{2}”上缺少“{0}”元数据。{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009:“{1}”中无法识别预处理器标记“{0}”。
diff --git a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
index 27b81bd4139f..abf2651cca49 100644
--- a/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
+++ b/src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
@@ -67,6 +67,11 @@
NETSDK1008: '{1}' 項目 '{2}' 上遺漏 '{0}' 中繼資料。{StrBegin="NETSDK1008: "}
+
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+
+ NETSDK1009: Unrecognized preprocessor token '{0}' in '{1}'.NETSDK1009: '{1}' 中的前置處理器語彙基元 '{0}' 無法辨識。
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ApplyImplicitVersions.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ApplyImplicitVersions.cs
new file mode 100644
index 000000000000..04ed9756e504
--- /dev/null
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/ApplyImplicitVersions.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Build.Framework;
+
+namespace Microsoft.NET.Build.Tasks
+{
+ public sealed class ApplyImplicitVersions : TaskBase
+ {
+ public string TargetFrameworkVersion { get; set; }
+
+ public bool TargetLatestRuntimePatch { get; set; }
+
+ public ITaskItem[] PackageReferences { get; set; } = Array.Empty();
+
+ public ITaskItem[] ImplicitPackageReferenceVersions { get; set; } = Array.Empty();
+
+ [Output]
+ public ITaskItem[] PackageReferencesToUpdate { get; private set; }
+
+ // This task runs both before restore and build, so if it logged warnings directly they could show up
+ // twice when building with implicit restore. So instead we generate the warnings here, and keep them
+ // in an item where they'll be logged in a target that runs before build, but not before restore.
+ [Output]
+ public string[] SdkBuildWarnings { get; private set; }
+
+ protected override void ExecuteCore()
+ {
+ List buildWarnings = new List();
+
+ var packageReferencesToUpdate = new List();
+
+ var implicitVersionTable = GetApplicableImplicitVersionTable();
+
+ foreach (var packageReference in PackageReferences)
+ {
+ ImplicitPackageReferenceVersion implicitVersion;
+ if (implicitVersionTable.TryGetValue(packageReference.ItemSpec, out implicitVersion))
+ {
+ string versionOnPackageReference = packageReference.GetMetadata(MetadataKeys.Version);
+ if (string.IsNullOrEmpty(versionOnPackageReference))
+ {
+ packageReference.SetMetadata(MetadataKeys.Version,
+ TargetLatestRuntimePatch ? implicitVersion.LatestVersion : implicitVersion.DefaultVersion);
+
+ packageReference.SetMetadata(MetadataKeys.IsImplicitlyDefined, "true");
+
+ packageReferencesToUpdate.Add(packageReference);
+ }
+ else if (!(packageReference.GetBooleanMetadata(MetadataKeys.AllowExplicitVersion) ?? false))
+ {
+ // NETSDK1071: A PackageReference to '{0}' specified a Version of `{1}`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs
+ buildWarnings.Add(string.Format(Strings.PackageReferenceVersionNotRecommended, packageReference.ItemSpec, versionOnPackageReference));
+ }
+ }
+ }
+
+ PackageReferencesToUpdate = packageReferencesToUpdate.ToArray();
+ SdkBuildWarnings = buildWarnings.ToArray();
+ }
+
+ private Dictionary GetApplicableImplicitVersionTable()
+ {
+ var result = new Dictionary();
+ foreach (var item in ImplicitPackageReferenceVersions)
+ {
+ var implicitPackageReferenceVersion = new ImplicitPackageReferenceVersion(item);
+
+ if (implicitPackageReferenceVersion.TargetFrameworkVersion == this.TargetFrameworkVersion)
+ {
+ result.Add(implicitPackageReferenceVersion.Name, implicitPackageReferenceVersion);
+ }
+ }
+
+ return result;
+ }
+
+ private sealed class ImplicitPackageReferenceVersion
+ {
+ private ITaskItem _item;
+
+ public ImplicitPackageReferenceVersion(ITaskItem item)
+ {
+ _item = item;
+ }
+
+ // The name / Package ID
+ public string Name => _item.ItemSpec;
+
+ // The target framework version that this item applies to
+ public string TargetFrameworkVersion => _item.GetMetadata("TargetFrameworkVersion");
+
+ public string DefaultVersion => _item.GetMetadata("DefaultVersion");
+
+ public string LatestVersion => _item.GetMetadata("LatestVersion");
+ }
+ }
+}
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForImplicitPackageReferenceOverrides.cs b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForImplicitPackageReferenceOverrides.cs
index 797469145139..0f41660272aa 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/CheckForImplicitPackageReferenceOverrides.cs
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/CheckForImplicitPackageReferenceOverrides.cs
@@ -9,8 +9,6 @@ namespace Microsoft.NET.Build.Tasks
{
public class CheckForImplicitPackageReferenceOverrides : TaskBase
{
- const string MetadataKeyForItemsToRemove = "IsImplicitlyDefined";
-
[Required]
public ITaskItem [] PackageReferenceItems { get; set; }
@@ -20,21 +18,41 @@ public class CheckForImplicitPackageReferenceOverrides : TaskBase
[Output]
public ITaskItem[] ItemsToRemove { get; set; }
+ [Output]
+ public ITaskItem[] ItemsToAdd { get; set; }
+
protected override void ExecuteCore()
{
var duplicateItems = PackageReferenceItems.GroupBy(i => i.ItemSpec, StringComparer.OrdinalIgnoreCase).Where(g => g.Count() > 1);
- var duplicateItemsToRemove = duplicateItems.SelectMany(g => g.Where(
- item => item.GetMetadata(MetadataKeyForItemsToRemove).Equals("true", StringComparison.OrdinalIgnoreCase)));
- ItemsToRemove = duplicateItemsToRemove.ToArray();
-
- foreach (var itemToRemove in ItemsToRemove)
+ if (duplicateItems.Any())
{
- string message = string.Format(CultureInfo.CurrentCulture, Strings.PackageReferenceOverrideWarning,
- itemToRemove.ItemSpec,
- MoreInformationLink);
-
- Log.LogWarning(message);
+ List itemsToRemove = new List();
+ List itemsToAdd = new List();
+ foreach (var duplicateItemGroup in duplicateItems)
+ {
+ foreach (var item in duplicateItemGroup)
+ {
+ if (item.GetMetadata(MetadataKeys.IsImplicitlyDefined).Equals("true", StringComparison.OrdinalIgnoreCase))
+ {
+ itemsToRemove.Add(item);
+
+ Log.LogWarning(Strings.PackageReferenceOverrideWarning, item.ItemSpec, MoreInformationLink);
+ }
+ else
+ {
+ // For the explicit items, we want to add metadata to them so that the ApplyImplicitVersions task
+ // won't generate another error. The easiest way to do this is to add them both to a list of
+ // items to remove, and then a list of items which gets added back.
+ itemsToRemove.Add(item);
+ item.SetMetadata(MetadataKeys.AllowExplicitVersion, "true");
+ itemsToAdd.Add(item);
+ }
+ }
+ }
+
+ ItemsToRemove = itemsToRemove.ToArray();
+ ItemsToAdd = itemsToAdd.ToArray();
}
}
}
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
index a737753cf7c2..956637da0ed7 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
@@ -341,7 +341,7 @@ internal byte[] HashSettings()
foreach (var implicitPackage in ExpectedPlatformPackages)
{
writer.Write(implicitPackage.ItemSpec ?? "");
- writer.Write(implicitPackage.GetMetadata(MetadataKeys.ExpectedVersion) ?? "");
+ writer.Write(implicitPackage.GetMetadata(MetadataKeys.Version) ?? "");
}
}
writer.Write(ProjectAssetsCacheFile);
@@ -849,10 +849,10 @@ bool hasTwoPeriods(string s)
if (_task.VerifyMatchingImplicitPackageVersion &&
_task.ExpectedPlatformPackages != null)
{
- foreach (var implicitPackge in _task.ExpectedPlatformPackages)
+ foreach (var implicitPackage in _task.ExpectedPlatformPackages)
{
- var packageName = implicitPackge.ItemSpec;
- var expectedVersion = implicitPackge.GetMetadata(MetadataKeys.ExpectedVersion);
+ var packageName = implicitPackage.ItemSpec;
+ var expectedVersion = implicitPackage.GetMetadata(MetadataKeys.Version);
if (string.IsNullOrEmpty(packageName) ||
string.IsNullOrEmpty(expectedVersion) ||
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets
index 3ca593b1fb99..1fee24a9b003 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.CrossGen.targets
@@ -258,15 +258,22 @@ Restores netcoreapp and publishes it to a temp directory
+
+
+
+
+
+
+ StorePackageVersion=%(PackageReferenceForCrossGen.Version);"/>
$(MSBuildAllProjects);$(MSBuildThisFileFullPath)
+
+
+ false
@@ -46,7 +49,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-
+
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets
index a89fca2790ef..a0553517df26 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets
@@ -76,85 +76,82 @@ Copyright (c) .NET Foundation. All rights reserved.
The TargetLatestRuntimePatch property can be set to true or false to explicitly opt in or out of the logic to roll forward
to the latest patch, regardless of whether the app is self-contained or framework-dependent.
- The RuntimeFrameworkVersion is where the actual version of the .NET Core runtime to target is stored. It is the version that is
- used in the implicit PackageReference to Microsoft.NETCore.App. The RuntimeFrameworkVersion can also be set explicitly, which
- will disable all the other logic that automatically selects the version of .NET Core to target.
+ The RuntimeFrameworkVersion is where the actual version of the .NET Core runtime to target can be set. If set, it will be
+ used in the implicit PackageReference to Microsoft.NETCore.App.
The framework version that is written to the runtimeconfig.json file is based on the actual resolved package version
of Microsoft.NETCore.App. This is to allow floating the verion number (ie the RuntimeFrameworkVersion could be set to
"2.0-*".
-->
-
-
-
-
-
- 1.0.10
- 1.1.7
- 2.0.6
-
-
-
- 1.0.5
- 1.1.2
-
-
- $(BundledNETCoreAppPackageVersion)
-
- $(_TargetFrameworkVersionWithoutV)
-
-
-
- $(LatestPatchVersionForNetCore1_0)
- $(LatestPatchVersionForNetCore1_1)
- $(LatestPatchVersionForNetCore2_0)
- $(LatestPatchVersionForNetCore2_1)
-
-
- $(BundledNETCoreAppPackageVersion)
-
- $(_TargetFrameworkVersionWithoutV)
- truefalse
-
- $(LatestNetCorePatchVersion)
- $(DefaultNetCorePatchVersion)
+
+ true
-
-
-
+
+
+
+ true
+ true
+
+
+
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
- true
-
+
+
+
+
+
+
+
+
+ $(_TargetFrameworkVersionWithoutV)
+
+
+
+
+
+
+
+
-
+
+
+
+
diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets
index 0c5c9ccb43c3..bbb14fcee06c 100644
--- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets
+++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets
@@ -197,6 +197,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<_PackAsToolShimRuntimeIdentifiers Include="$(PackAsToolShimRuntimeIdentifiers)"/>
+
+
+
+
+ l.Name == libraryName);
+
+ return lockFileLibrary.Version;
+ }
+ }
+}
diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs
index 5957071f09d5..ca568ae07db0 100644
--- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs
+++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatAPublishedDepsJsonShouldContainVersionInformation.cs
@@ -15,6 +15,9 @@
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Newtonsoft.Json.Linq;
+using NuGet.Common;
+using NuGet.Frameworks;
+using NuGet.ProjectModel;
using Xunit;
using Xunit.Abstractions;
@@ -254,15 +257,14 @@ string GetRollForwardNetCoreAppVersion()
var testAsset = _testAssetsManager.CreateTestProject(testProject)
.Restore(Log, testProject.Name);
- var getValuesCommand = new GetValuesCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name),
- testProject.TargetFrameworks, "RuntimeFrameworkVersion")
- {
- ShouldCompile = false
- };
- getValuesCommand.Execute().Should().Pass();
+ LockFile lockFile = LockFileUtilities.GetLockFile(Path.Combine(testAsset.TestRoot, testProject.Name,
+ "obj", "project.assets.json"), NullLogger.Instance);
+
+ var target = lockFile.GetTarget(NuGetFramework.Parse(testProject.TargetFrameworks), null);
+ var netCoreAppLibrary = target.Libraries.Single(l => l.Name == "Microsoft.NETCore.App");
- return getValuesCommand.GetValues().Single();
+ return netCoreAppLibrary.Version.ToString();
}
}
}
diff --git a/src/Tests/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs b/src/Tests/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
index 6e91bd2f7d77..0ffb53c2e53d 100644
--- a/src/Tests/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
+++ b/src/Tests/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs
@@ -145,9 +145,13 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder)
foreach (TestPackageReference packageReference in PackageReferences)
{
- packageReferenceItemGroup.Add(new XElement(ns + "PackageReference",
- new XAttribute("Include", $"{packageReference.ID}"),
- new XAttribute("Version", $"{packageReference.Version}")));
+ var packageReferenceElement = new XElement(ns + "PackageReference",
+ new XAttribute("Include", packageReference.ID));
+ if (packageReference.Version != null)
+ {
+ packageReferenceElement.Add(new XAttribute("Version", packageReference.Version));
+ }
+ packageReferenceItemGroup.Add(packageReferenceElement);
}
foreach (TestPackageReference dotnetCliToolReference in DotNetCliToolReferences)