diff options
author | Ankit Mishra <anmishr@microsoft.com> | 2018-05-22 00:39:49 +0300 |
---|---|---|
committer | Ankit Mishra <anmishr@microsoft.com> | 2018-05-22 00:39:49 +0300 |
commit | 0912cc96c0120da12e1975d2a96cbc8336e32dbf (patch) | |
tree | bbddddcb0023bad54e4728cb081574ee6303585f | |
parent | cf4b0a12cf1f75e0654f28c2a9020251c41d126a (diff) |
Improving error message for RIDS in lock file
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs | 25 | ||||
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs | 20 | ||||
-rw-r--r-- | src/Microsoft.NuGet.Build.Tasks/Strings.resx | 8 |
3 files changed, 48 insertions, 5 deletions
diff --git a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs index 7de0f02..aa56fe5 100644 --- a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs +++ b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs @@ -36,6 +36,8 @@ namespace Microsoft.NuGet.Build.Tasks internal const string NuGetAssetTypeRuntime = "runtime"; internal const string NuGetAssetTypeResource = "resource"; + internal const string RuntimeIdentifiersProperty = "RuntimeIdentifiers"; + private readonly List<ITaskItem> _analyzers = new List<ITaskItem>(); private readonly List<ITaskItem> _copyLocalItems = new List<ITaskItem>(); private readonly List<ITaskItem> _references = new List<ITaskItem>(); @@ -715,7 +717,18 @@ namespace Microsoft.NuGet.Build.Tasks private void GiveErrorForMissingRuntimeIdentifier() { - string runtimePiece = '"' + RuntimeIdentifier + "\": { }"; + var runtimePiece = RuntimeIdentifier; + var runtimesSection = $"<{RuntimeIdentifiersProperty}>{RuntimeIdentifier}</{RuntimeIdentifiersProperty}>"; + var missingRuntimeInRuntimesErrorString = nameof(Strings.MissingSpecificRuntimeIdentifier); + var missingRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifiers); + + if (IsLockFileProjectJsonBased(ProjectLockFile)) + { + runtimePiece = '"' + RuntimeIdentifier + "\": { }"; + runtimesSection = "\"runtimes\": { " + runtimePiece + " }"; + missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeInRuntimesSection); + missingRuntimesErrorString = nameof(Strings.MissingRuntimesSection); + } bool hasRuntimesSection; try @@ -734,12 +747,11 @@ namespace Microsoft.NuGet.Build.Tasks if (hasRuntimesSection) { - ThrowExceptionIfNotAllowingFallback(nameof(Strings.MissingRuntimeInRuntimesSection), RuntimeIdentifier, runtimePiece); + ThrowExceptionIfNotAllowingFallback(missingRuntimeInRuntimesErrorString, RuntimeIdentifier, runtimePiece); } else { - var runtimesSection = "\"runtimes\": { " + runtimePiece + " }"; - ThrowExceptionIfNotAllowingFallback(nameof(Strings.MissingRuntimesSection), runtimesSection); + ThrowExceptionIfNotAllowingFallback(missingRuntimesErrorString, runtimesSection); } } @@ -1027,5 +1039,10 @@ namespace Microsoft.NuGet.Build.Tasks return String.Empty; } } + + private static bool IsLockFileProjectJsonBased(string lockFilePath) + { + return lockFilePath.EndsWith("lock.json", StringComparison.OrdinalIgnoreCase); + } } } diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs index 9b3de63..429667d 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs +++ b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.NuGet.Build.Tasks { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { @@ -115,6 +115,15 @@ namespace Microsoft.NuGet.Build.Tasks { } /// <summary> + /// Looks up a localized string similar to Your project csproj file doesn't have the "RuntimeIdentifiers" property. You should add '{0}' to your project csproj file and then re-run NuGet restore.. + /// </summary> + internal static string MissingRuntimeIdentifiers { + get { + return ResourceManager.GetString("MissingRuntimeIdentifiers", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to Your project.json doesn't list '{0}' as a targeted runtime. You should add '{1}' inside your "runtimes" section in your project.json, and then re-run NuGet restore.. /// </summary> internal static string MissingRuntimeInRuntimesSection { @@ -133,6 +142,15 @@ namespace Microsoft.NuGet.Build.Tasks { } /// <summary> + /// Looks up a localized string similar to Your project csproj file doesn't list '{0}' as a targeted runtime. You should add '{1}' to the "RuntimeIdentifiers" property in your project csproj file and then re-run NuGet restore.. + /// </summary> + internal static string MissingSpecificRuntimeIdentifier { + get { + return ResourceManager.GetString("MissingSpecificRuntimeIdentifier", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to No targets could be found in the lock file. Make sure you have a supports or runtimes section i your project.json file.. /// </summary> internal static string NoTargetsInLockFile { diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.resx b/src/Microsoft.NuGet.Build.Tasks/Strings.resx index 16d5d64..4490c3b 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Strings.resx +++ b/src/Microsoft.NuGet.Build.Tasks/Strings.resx @@ -135,12 +135,20 @@ <data name="MissingProjectReference" xml:space="preserve"> <value>The project.json is referencing the project '{0}', but an output path was not specified on an item in the {1} property.</value> </data> + <data name="MissingRuntimeIdentifiers" xml:space="preserve"> + <value>Your project csproj file doesn't have the "RuntimeIdentifiers" property. You should add '{0}' to your project csproj file and then re-run NuGet restore.</value> + <comment>0 - RID</comment> + </data> <data name="MissingRuntimeInRuntimesSection" xml:space="preserve"> <value>Your project.json doesn't list '{0}' as a targeted runtime. You should add '{1}' inside your "runtimes" section in your project.json, and then re-run NuGet restore.</value> </data> <data name="MissingRuntimesSection" xml:space="preserve"> <value>Your project.json doesn't have a runtimes section. You should add '{0}' to your project.json and then re-run NuGet restore.</value> </data> + <data name="MissingSpecificRuntimeIdentifier" xml:space="preserve"> + <value>Your project csproj file doesn't list '{0}' as a targeted runtime. You should add '{1}' to the "RuntimeIdentifiers" property in your project csproj file and then re-run NuGet restore.</value> + <comment>0/1 - RID</comment> + </data> <data name="NoTargetsInLockFile" xml:space="preserve"> <value>No targets could be found in the lock file. Make sure you have a supports or runtimes section i your project.json file.</value> </data> |