@@ -240,8 +240,10 @@ public static ProjectData Create(MSB.Evaluation.Project project)
240
240
documentationFile , preprocessorSymbolNames , suppressedDiagnosticIds , warningsAsErrors , warningsNotAsErrors , signAssembly , assemblyOriginatorKeyFile , treatWarningsAsErrors , defaultNamespace , runAnalyzers , runAnalyzersDuringLiveAnalysis , ruleset : null ) ;
241
241
}
242
242
243
- public static ProjectData Create ( MSB . Execution . ProjectInstance projectInstance , MSB . Evaluation . Project project )
243
+ public static ProjectData Create ( string projectFilePath , MSB . Execution . ProjectInstance projectInstance , MSB . Evaluation . Project project )
244
244
{
245
+ var projectFolderPath = Path . GetDirectoryName ( projectFilePath ) ;
246
+
245
247
var guid = PropertyConverter . ToGuid ( projectInstance . GetPropertyValue ( PropertyNames . ProjectGuid ) ) ;
246
248
var name = projectInstance . GetPropertyValue ( PropertyNames . ProjectName ) ;
247
249
var assemblyName = projectInstance . GetPropertyValue ( PropertyNames . AssemblyName ) ;
@@ -286,41 +288,32 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance,
286
288
287
289
var projectReferences = ImmutableArray . CreateBuilder < string > ( ) ;
288
290
var projectReferenceAliases = ImmutableDictionary . CreateBuilder < string , string > ( ) ;
289
- var projectReferencesAdded = new HashSet < string > ( ) ;
290
- foreach ( var projectReferenceItem in projectInstance . GetItems ( ItemNames . ProjectReference ) )
291
- {
292
- var fullPath = projectReferenceItem . GetMetadataValue ( MetadataNames . FullPath ) ;
293
-
294
- if ( IsCSharpProject ( fullPath ) && projectReferencesAdded . Add ( fullPath ) )
295
- {
296
- projectReferences . Add ( fullPath ) ;
297
-
298
- var aliases = projectReferenceItem . GetMetadataValue ( MetadataNames . Aliases ) ;
299
- if ( ! string . IsNullOrEmpty ( aliases ) )
300
- {
301
- projectReferenceAliases [ fullPath ] = aliases ;
302
- }
303
- }
304
- }
305
291
306
292
var references = ImmutableArray . CreateBuilder < string > ( ) ;
307
293
var referenceAliases = ImmutableDictionary . CreateBuilder < string , string > ( ) ;
308
294
foreach ( var referencePathItem in projectInstance . GetItems ( ItemNames . ReferencePath ) )
309
295
{
310
296
var referenceSourceTarget = referencePathItem . GetMetadataValue ( MetadataNames . ReferenceSourceTarget ) ;
297
+ var aliases = referencePathItem . GetMetadataValue ( MetadataNames . Aliases ) ;
311
298
299
+ // If this reference came from a project reference, count it as such. We never want to directly look
300
+ // at the ProjectReference items in the project, as those don't always create project references
301
+ // if things like OutputItemType or ReferenceOutputAssembly are set. It's also possible that other
302
+ // MSBuild logic is adding or removing properties too.
312
303
if ( StringComparer . OrdinalIgnoreCase . Equals ( referenceSourceTarget , ItemNames . ProjectReference ) )
313
304
{
314
- // If the reference was sourced from a project reference, we have two choices:
315
- //
316
- // 1. If the reference is a C# project reference, we shouldn't add it because it'll just duplicate
317
- // the project reference.
318
- // 2. If the reference is *not* a C# project reference, we should keep this reference because the
319
- // project reference was already removed.
320
-
321
- var originalItemSpec = referencePathItem . GetMetadataValue ( MetadataNames . OriginalItemSpec ) ;
322
- if ( originalItemSpec . EndsWith ( ".csproj" , StringComparison . OrdinalIgnoreCase ) )
305
+ var projectReferenceOriginalItemSpec = referencePathItem . GetMetadataValue ( MetadataNames . ProjectReferenceOriginalItemSpec ) ;
306
+ if ( projectReferenceOriginalItemSpec . EndsWith ( ".csproj" , StringComparison . OrdinalIgnoreCase ) )
323
307
{
308
+ var projectReferenceFilePath = Path . GetFullPath ( Path . Combine ( projectFolderPath , projectReferenceOriginalItemSpec ) ) ;
309
+
310
+ projectReferences . Add ( projectReferenceFilePath ) ;
311
+
312
+ if ( ! string . IsNullOrEmpty ( aliases ) )
313
+ {
314
+ projectReferenceAliases [ projectReferenceFilePath ] = aliases ;
315
+ }
316
+
324
317
continue ;
325
318
}
326
319
}
@@ -330,7 +323,6 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance,
330
323
{
331
324
references . Add ( fullPath ) ;
332
325
333
- var aliases = referencePathItem . GetMetadataValue ( MetadataNames . Aliases ) ;
334
326
if ( ! string . IsNullOrEmpty ( aliases ) )
335
327
{
336
328
referenceAliases [ fullPath ] = aliases ;
@@ -395,9 +387,6 @@ private static RuleSet ResolveRulesetIfAny(MSB.Execution.ProjectInstance project
395
387
return null ;
396
388
}
397
389
398
- private static bool IsCSharpProject ( string filePath )
399
- => filePath . EndsWith ( ".csproj" , StringComparison . OrdinalIgnoreCase ) ;
400
-
401
390
private static bool FileNameIsNotGenerated ( string filePath )
402
391
=> ! Path . GetFileName ( filePath ) . StartsWith ( "TemporaryGeneratedFile_" , StringComparison . OrdinalIgnoreCase ) ;
403
392
0 commit comments