From 90240a431bb058ff08279bf0e00d38b059560913 Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Fri, 25 Mar 2016 16:14:57 -0700 Subject: [PATCH] Compute msbuild project path relative to root project path --- .../ProjectContextBuilder.cs | 2 +- .../Resolution/MSBuildDependencyProvider.cs | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index ab5400914..aeb423a46 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectModel if (target != null) { var nugetPackageResolver = new PackageDependencyProvider(PackagesDirectory, frameworkReferenceResolver); - var msbuildProjectResolver = new MSBuildDependencyProvider(ProjectResolver); + var msbuildProjectResolver = new MSBuildDependencyProvider(Project ,ProjectResolver); ScanLibraries(target, lockFileLookup, libraries, msbuildProjectResolver, nugetPackageResolver, projectResolver); } } diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs index 33949c3ca..e67e1c313 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs @@ -12,10 +12,12 @@ namespace Microsoft.DotNet.ProjectModel.Resolution { public class MSBuildDependencyProvider { + private readonly Project _rootProject; private readonly Func _projectResolver; - public MSBuildDependencyProvider(Func projectResolver) + public MSBuildDependencyProvider(Project rootProject, Func projectResolver) { + _rootProject = rootProject; _projectResolver = projectResolver; } @@ -28,13 +30,13 @@ namespace Microsoft.DotNet.ProjectModel.Resolution var dependencies = new List(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); PopulateDependencies(dependencies, targetLibrary, targetFramework); - var path = Path.GetDirectoryName(Path.GetFullPath(projectLibrary.MSBuildProject)); - var exists = Directory.Exists(path); + var msbuildProjectPath = GetMSbuildProjectPath(projectLibrary); + var exists = Directory.Exists(msbuildProjectPath); var projectFile = projectLibrary.Path == null ? null : _projectResolver(projectLibrary.Path); var msbuildPackageDescription = new MSBuildProjectDescription( - path, + msbuildProjectPath, projectLibrary, targetLibrary, projectFile, @@ -45,6 +47,20 @@ namespace Microsoft.DotNet.ProjectModel.Resolution return msbuildPackageDescription; } + private string GetMSbuildProjectPath(LockFileProjectLibrary projectLibrary) + { + if (_rootProject == null) + { + throw new InvalidOperationException("Root xproj project does not exist. Cannot compute the path of its referenced csproj projects."); + } + + var rootProjectPath = Path.GetDirectoryName(_rootProject.ProjectFilePath); + var msbuildProjectFilePath = Path.Combine(rootProjectPath, projectLibrary.MSBuildProject); + var msbuildProjectPath = Path.GetDirectoryName(Path.GetFullPath(msbuildProjectFilePath)); + + return msbuildProjectPath; + } + private void PopulateDependencies( List dependencies, LockFileTargetLibrary targetLibrary,