Skip to content

Commit e546cd5

Browse files
Give a more graceful error message if the lock file is broken
1 parent 0356fbd commit e546cd5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ private IEnumerable<NuGetPackageObject> GetPackagesFromTarget(JObject lockFile,
885885

886886
Func<string> fullPackagePathGenerator;
887887

888+
if (libraryObject == null)
889+
{
890+
throw new ExceptionFromResource(nameof(Strings.MissingPackageInTargetsSection), package.Key);
891+
}
892+
888893
// If this is a project then we need to figure out it's relative output path
889894
if ((string)libraryObject["type"] == "project")
890895
{

src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.NuGet.Build.Tasks/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
<data name="MissingMSBuildPathInProjectPackage" xml:space="preserve">
133133
<value>Your project is consuming assets from the project '{0}' but no MSBuild project is found in the project.lock.json. Check the project references in your project file, and re-run NuGet restore.</value>
134134
</data>
135+
<data name="MissingPackageInTargetsSection" xml:space="preserve">
136+
<value>The package '{0}' could not be found in the libraries section of the lock file. This may indicate your lock file is corrupted.</value>
137+
</data>
135138
<data name="MissingProjectReference" xml:space="preserve">
136139
<value>The project.json is referencing the project '{0}', but an output path was not specified on an item in the {1} property.</value>
137140
</data>

0 commit comments

Comments
 (0)