Skip to content

Commit

Permalink
Handle more than one NuGet package source being defined
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Nov 6, 2017
1 parent d5e265b commit a603d3e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Blazor.Compiler/ProjectReferenceUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ public static string[] FindReferencedAssemblies(string copyFromProjectRoot, Opti
}

var assetsInfo = (JsonDict)Json.Deserialize(File.ReadAllText(assetsJsonPath));
var packageFolders = ((JsonDict)assetsInfo["packageFolders"]);
if (packageFolders.Count != 1)
var packageFolders = ((JsonDict)assetsInfo["packageFolders"]).Keys.ToList();
if (!packageFolders.Any())
{
throw new InvalidDataException($"Expected to find exactly 1 package folder, but found {packageFolders.Count}.");
throw new InvalidDataException($"Expected to find package folders, but found none.");
}
var packageFolder = packageFolders.Keys.Single();

var targets = ((JsonDict)assetsInfo["targets"]);
if (targets.Count != 1)
Expand Down Expand Up @@ -56,7 +55,21 @@ public static string[] FindReferencedAssemblies(string copyFromProjectRoot, Opti
if (referenceType == "package")
{
var packageNameAndVersion = referenceKvp.Key;
return compileItems.Select(item => Path.Combine(packageFolder, packageNameAndVersion, item));

return compileItems.Select(item =>
{
var partialPath = Path.Combine(packageNameAndVersion, item);
foreach (var packageFolder in packageFolders)
{
var candidateFilename = Path.Combine(packageFolder, partialPath);
if (File.Exists(candidateFilename))
{
return candidateFilename;
}
}

throw new InvalidDataException($"Could not find {partialPath} in any of the package folders:\n{string.Join('\n', packageFolders)}");
});
}
else if (referenceType == "project")
{
Expand Down

0 comments on commit a603d3e

Please sign in to comment.