Skip to content

Commit

Permalink
Use ProjectReferenceOriginalItemSpec for getting package reference path
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich authored and jasonmalinowski committed Sep 28, 2020
1 parent 7f45a59 commit 1c487ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/OmniSharp.MSBuild/ProjectFile/MetadataNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal static class MetadataNames
public const string FullPath = nameof(FullPath);
public const string IsImplicitlyDefined = nameof(IsImplicitlyDefined);
public const string Project = nameof(Project);
public const string MSBuildSourceProjectFile = nameof(MSBuildSourceProjectFile);
public const string ProjectReferenceOriginalItemSpec = nameof(ProjectReferenceOriginalItemSpec);
public const string ReferenceSourceTarget = nameof(ReferenceSourceTarget);
public const string Version = nameof(Version);
public const string Aliases = nameof(Aliases);
Expand Down
14 changes: 9 additions & 5 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ public static ProjectData Create(MSB.Evaluation.Project project)
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, warningsAsErrors, warningsNotAsErrors, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, runAnalyzers, runAnalyzersDuringLiveAnalysis, ruleset: null);
}

public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project)
public static ProjectData Create(string projectFilePath, MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project)
{
var projectFolderPath = Path.GetDirectoryName(projectFilePath);

var guid = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
var name = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
var assemblyName = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
Expand Down Expand Up @@ -300,14 +302,16 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance,
// MSBuild logic is adding or removing properties too.
if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
{
var sourceProjectFile = referencePathItem.GetMetadataValue(MetadataNames.MSBuildSourceProjectFile);
if (sourceProjectFile.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
var projectReferenceOriginalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.ProjectReferenceOriginalItemSpec);
if (projectReferenceOriginalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
{
projectReferences.Add(sourceProjectFile);
var projectReferenceFilePath = Path.GetFullPath(Path.Combine(projectFolderPath, projectReferenceOriginalItemSpec));

projectReferences.Add(projectReferenceFilePath);

if (!string.IsNullOrEmpty(aliases))
{
projectReferenceAliases[sourceProjectFile] = aliases;
projectReferenceAliases[projectReferenceFilePath] = aliases;
}

continue;
Expand Down
4 changes: 2 additions & 2 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static (ProjectFileInfo, ImmutableArray<MSBuildDiagnostic>, ProjectLoaded
return (null, diagnostics, null);
}

var data = ProjectData.Create(projectInstance, project);
var data = ProjectData.Create(filePath, projectInstance, project);
var projectFileInfo = new ProjectFileInfo(projectIdInfo, filePath, data, sessionId, dotNetInfo);
var eventArgs = new ProjectLoadedEventArgs(projectIdInfo.Id,
project,
Expand All @@ -143,7 +143,7 @@ public static (ProjectFileInfo, ImmutableArray<MSBuildDiagnostic>, ProjectLoaded
return (null, diagnostics, null);
}

var data = ProjectData.Create(projectInstance, project);
var data = ProjectData.Create(FilePath, projectInstance, project);
var projectFileInfo = new ProjectFileInfo(ProjectIdInfo, FilePath, data, SessionId, DotNetInfo);
var eventArgs = new ProjectLoadedEventArgs(Id,
project,
Expand Down

0 comments on commit 1c487ea

Please sign in to comment.