Skip to content

Commit 56c2896

Browse files
authored
Merge pull request #14848 from Pilchie/Fix14584-VBMscorlibDPL
Use ResolveMetadataReferences in DPL
2 parents bf0e9d7 + ece7ae1 commit 56c2896

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProjectTracker_IVsSolutionEvents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using Microsoft.VisualStudio.Shell.Interop;
66
using Roslyn.Utilities;
7+
using Microsoft.CodeAnalysis.Host;
78

89
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
910
{
@@ -25,8 +26,7 @@ int IVsSolutionEvents.OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
2526

2627
if (IsDeferredSolutionLoadEnabled())
2728
{
28-
var deferredProjectWorkspaceService = _workspaceServices.GetService<IDeferredProjectWorkspaceService>();
29-
LoadSolutionFromMSBuildAsync(deferredProjectWorkspaceService, _solutionParsingCancellationTokenSource.Token).FireAndForget();
29+
LoadSolutionFromMSBuildAsync(_solutionParsingCancellationTokenSource.Token).FireAndForget();
3030
}
3131

3232
return VSConstants.S_OK;

src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProjectTracker_IVsSolutionLoadEvents.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ int IVsSolutionLoadEvents.OnBeforeOpenSolution(string pszSolutionFilename)
3434
}
3535

3636
private async Task LoadSolutionFromMSBuildAsync(
37-
IDeferredProjectWorkspaceService deferredProjectWorkspaceService,
3837
CancellationToken cancellationToken)
3938
{
4039
AssertIsForeground();
4140
InitializeOutputPane();
4241

4342
// Continue on the UI thread for these operations, since we are touching the VisualStudioWorkspace, etc.
44-
await PopulateWorkspaceFromDeferredProjectInfoAsync(deferredProjectWorkspaceService, cancellationToken).ConfigureAwait(true);
43+
await PopulateWorkspaceFromDeferredProjectInfoAsync(cancellationToken).ConfigureAwait(true);
4544
}
4645

4746
[Conditional("DEBUG")]
@@ -104,7 +103,6 @@ int IVsSolutionLoadEvents.OnAfterBackgroundSolutionLoadComplete()
104103
}
105104

106105
private async Task PopulateWorkspaceFromDeferredProjectInfoAsync(
107-
IDeferredProjectWorkspaceService deferredProjectWorkspaceService,
108106
CancellationToken cancellationToken)
109107
{
110108
// NOTE: We need to check cancellationToken after each await, in case the user has
@@ -127,6 +125,7 @@ private async Task PopulateWorkspaceFromDeferredProjectInfoAsync(
127125
if (solutionConfig != null)
128126
{
129127
// Capture the context so that we come back on the UI thread, and do the actual project creation there.
128+
var deferredProjectWorkspaceService = _workspaceServices.GetService<IDeferredProjectWorkspaceService>();
130129
projectInfos = await deferredProjectWorkspaceService.GetDeferredProjectInfoForConfigurationAsync(
131130
$"{solutionConfig.Name}|{solutionConfig.PlatformName}",
132131
cancellationToken).ConfigureAwait(true);
@@ -139,11 +138,13 @@ private async Task PopulateWorkspaceFromDeferredProjectInfoAsync(
139138
OutputToOutputWindow($"Creating projects - start");
140139
start = DateTimeOffset.UtcNow;
141140
var targetPathsToProjectPaths = BuildTargetPathMap(projectInfos);
141+
var analyzerAssemblyLoader = _workspaceServices.GetRequiredService<IAnalyzerService>().GetLoader();
142142
foreach (var projectFilename in projectInfos.Keys)
143143
{
144144
cancellationToken.ThrowIfCancellationRequested();
145145
GetOrCreateProjectFromArgumentsAndReferences(
146146
workspaceProjectContextFactory,
147+
analyzerAssemblyLoader,
147148
projectFilename,
148149
projectInfos,
149150
targetPathsToProjectPaths);
@@ -185,6 +186,7 @@ private void OutputToOutputWindow(string message)
185186

186187
private AbstractProject GetOrCreateProjectFromArgumentsAndReferences(
187188
IWorkspaceProjectContextFactory workspaceProjectContextFactory,
189+
IAnalyzerAssemblyLoader analyzerAssemblyLoader,
188190
string projectFilename,
189191
IReadOnlyDictionary<string, DeferredProjectInformation> allProjectInfos,
190192
IReadOnlyDictionary<string, string> targetPathsToProjectPaths)
@@ -263,6 +265,7 @@ private AbstractProject GetOrCreateProjectFromArgumentsAndReferences(
263265
hierarchy: null,
264266
binOutputPath: outputPath);
265267

268+
project = (AbstractProject)projectContext;
266269
projectContext.SetOptions(projectInfo.CommandLineArguments.Join(" "));
267270

268271
foreach (var sourceFile in commandLineArguments.SourceFiles)
@@ -287,6 +290,7 @@ private AbstractProject GetOrCreateProjectFromArgumentsAndReferences(
287290
{
288291
referencedProject = GetOrCreateProjectFromArgumentsAndReferences(
289292
workspaceProjectContextFactory,
293+
analyzerAssemblyLoader,
290294
projectReferencePath,
291295
allProjectInfos,
292296
targetPathsToProjectPaths);
@@ -322,22 +326,30 @@ private AbstractProject GetOrCreateProjectFromArgumentsAndReferences(
322326
}
323327
}
324328

325-
foreach (var reference in commandLineArguments.MetadataReferences)
329+
foreach (var reference in commandLineArguments.ResolveMetadataReferences(project.CurrentCompilationOptions.MetadataReferenceResolver))
326330
{
331+
// Some references may fail to be resolved - if they are, we'll still pass them
332+
// through, in case they come into existence later (they may be built by other
333+
// parts of the build system).
334+
var unresolvedReference = reference as UnresolvedMetadataReference;
335+
var path = unresolvedReference == null
336+
? ((PortableExecutableReference)reference).FilePath
337+
: unresolvedReference.Reference;
338+
327339
string possibleProjectReference;
328-
if (targetPathsToProjectPaths.TryGetValue(reference.Reference, out possibleProjectReference) &&
340+
if (targetPathsToProjectPaths.TryGetValue(path, out possibleProjectReference) &&
329341
addedProjectReferences.Contains(possibleProjectReference))
330342
{
331343
// We already added a P2P reference for this, we don't need to add the file reference too.
332344
continue;
333345
}
334346

335-
projectContext.AddMetadataReference(reference.Reference, reference.Properties);
347+
projectContext.AddMetadataReference(path, reference.Properties);
336348
}
337349

338-
foreach (var reference in commandLineArguments.AnalyzerReferences)
350+
foreach (var reference in commandLineArguments.ResolveAnalyzerReferences(analyzerAssemblyLoader))
339351
{
340-
var path = reference.FilePath;
352+
var path = reference.FullPath;
341353
if (!PathUtilities.IsAbsolute(path))
342354
{
343355
path = PathUtilities.CombineAbsoluteAndRelativePaths(

0 commit comments

Comments
 (0)