Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BaseIntermediatePath for project.assets.json #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,18 @@ public Container GetContainer()

try
{
projectNode.OutputPaths = FindOutputPaths();
(projectNode.OutputPaths, var baseIntermediatePath) = FindOutputPaths();
if (!string.IsNullOrEmpty(baseIntermediatePath))
{
Options.ProjectAssetsJsonPath =
CreateProjectAssetsJsonPathFromIntermediate(baseIntermediatePath);
}
}
catch (Exception e)
{
Console.WriteLine("Unable to determine output paths for this project.");
}


bool packagesConfigExists = !String.IsNullOrWhiteSpace(Options.PackagesConfigPath) && File.Exists(Options.PackagesConfigPath);
bool projectJsonExists = !String.IsNullOrWhiteSpace(Options.ProjectJsonPath) && File.Exists(Options.ProjectJsonPath);
bool projectJsonLockExists = !String.IsNullOrWhiteSpace(Options.ProjectJsonLockPath) && File.Exists(Options.ProjectJsonLockPath);
Expand Down Expand Up @@ -265,7 +269,7 @@ public Container GetContainer()
}


public List<String> FindOutputPaths()
public ProjectInfo FindOutputPaths()
{
//TODO: Move to a new class (OutputPathResolver?)
Console.WriteLine("Attempting to parse configuration output paths.");
Expand All @@ -275,6 +279,9 @@ public List<String> FindOutputPaths()
Microsoft.Build.Evaluation.Project proj = new Microsoft.Build.Evaluation.Project(Options.TargetPath);
List<string> outputPaths = new List<string>();
List<string> configurations;
var intermediatePath = proj.GetPropertyValue("BaseIntermediateOutputPath") ?? "obj";
var fullIntermediatePath = PathUtil.Combine(proj.DirectoryPath, intermediatePath);
Console.WriteLine("Intermediate path: " + fullIntermediatePath);
proj.ConditionedProperties.TryGetValue("Configuration", out configurations);
if (configurations == null) configurations = new List<string>();
foreach (var config in configurations)
Expand All @@ -288,12 +295,12 @@ public List<String> FindOutputPaths()
}
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.UnloadProject(proj);
Console.WriteLine($"Found {outputPaths.Count} paths.");
return outputPaths;
return new ProjectInfo(outputPaths, fullIntermediatePath);
}
catch (Exception e)
{
Console.WriteLine("Skipping configuration output paths.");
return new List<string>() { };
return new ProjectInfo(new List<string>() { }, string.Empty);
}
}

Expand Down Expand Up @@ -381,7 +388,12 @@ private string CreateProjectAssetsJsonPath(string projectDirectory)
{
return PathUtil.Combine(projectDirectory, "obj", "project.assets.json");
}


private string CreateProjectAssetsJsonPathFromIntermediate(string intermediatePath)
{
return PathUtil.Combine(intermediatePath, "project.assets.json");
}

private string CreateDirectoryPackagesPropsPath(string projectDirectory)
{
return PathUtil.Combine(projectDirectory, "Directory.Packages.props");
Expand All @@ -404,5 +416,7 @@ private string GetProjectAssetsJsonPathFromNugetProperty(string projectDirectory
}
return null;
}

public record ProjectInfo(List<string> Output, string BaseIntermediatePath);
}
}