in src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs [731:773]
private void GiveErrorForMissingRuntimeIdentifier()
{
var runtimePiece = RuntimeIdentifier;
var runtimesSection = $"<{RuntimeIdentifiersProperty}>{RuntimeIdentifier}</{RuntimeIdentifiersProperty}>";
var missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierInProjectFile);
var missingRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierPropertyInProjectFile);
if (IsLockFileProjectJsonBased(ProjectLockFile))
{
runtimePiece = '"' + RuntimeIdentifier + "\": { }";
runtimesSection = "\"runtimes\": { " + runtimePiece + " }";
missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeInProjectJson);
missingRuntimesErrorString = nameof(Strings.MissingRuntimesSectionInProjectJson);
}
bool hasRuntimesSection = true;
try
{
// try reading the project.json file only of the project is project.json based
if (IsLockFileProjectJsonBased(ProjectLockFile))
{
using (var streamReader = new StreamReader(ProjectLockFile.Replace(".lock.json", ".json")))
{
var jsonFile = JObject.Load(new JsonTextReader(streamReader));
hasRuntimesSection = jsonFile["runtimes"] != null;
}
}
}
catch
{
// User has a bad file, locked file, no file at all, etc. We'll just assume they have one.
hasRuntimesSection = true;
}
if (hasRuntimesSection)
{
ThrowExceptionIfNotAllowingFallback(missingRuntimeInRuntimesErrorString, RuntimeIdentifier, runtimePiece);
}
else
{
ThrowExceptionIfNotAllowingFallback(missingRuntimesErrorString, runtimesSection);
}
}