static Tuple <List <NuGetFramework>, ProjectRestoreReference> GetProjectRestoreReference( ProjectReference item, IDotNetProject project, ILogger logger) { var frameworks = GetFrameworks(project).ToList(); var referencedProject = project.ParentSolution.ResolveProject(item); if (referencedProject == null) { logger.LogWarning(GettextCatalog.GetString("WARNING: Unable to resolve project '{0}' referenced by '{1}'.", item.Include, project.Name)); return(null); } var reference = new ProjectRestoreReference() { ProjectPath = referencedProject.FileName, ProjectUniqueName = referencedProject.FileName, }; ApplyIncludeFlags( reference, item.Metadata.GetValue("IncludeAssets"), item.Metadata.GetValue("ExcludeAssets"), item.Metadata.GetValue("PrivateAssets")); return(new Tuple <List <NuGetFramework>, ProjectRestoreReference> (frameworks, reference)); }
public void ProjectRestoreMetadataFrameworkInfoCloneTest() { //Set up var projectReference = new ProjectRestoreReference(); projectReference.ProjectPath = "Path"; projectReference.ProjectUniqueName = "ProjectUniqueName"; projectReference.IncludeAssets = LibraryModel.LibraryIncludeFlags.All; projectReference.ExcludeAssets = LibraryModel.LibraryIncludeFlags.Analyzers; projectReference.PrivateAssets = LibraryModel.LibraryIncludeFlags.Build; var nugetFramework = NuGetFramework.Parse("net461"); var originalPRMFI = new ProjectRestoreMetadataFrameworkInfo(nugetFramework); originalPRMFI.ProjectReferences = new List <ProjectRestoreReference>() { projectReference }; // Act var clone = originalPRMFI.Clone(); // Assert Assert.Equal(clone, originalPRMFI); Assert.False(object.ReferenceEquals(originalPRMFI, clone)); // Act projectReference.ProjectPath = "NewPath"; // Assert Assert.NotEqual(clone, originalPRMFI); }
public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync( Common.ILogger logger, CancellationToken _) { var results = new List <ProjectRestoreReference>(); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var vcProject = await _vcProject.GetValueAsync(); var references = vcProject.VCReferences as VCReferences; var projectReferences = references.GetReferencesOfType((uint)vcRefType.VCRT_PROJECT); bool hasMissingReferences = false; foreach (var reference in projectReferences) { try { var vcReference = reference as VCProjectReference; if (vcReference.UseInBuild) { if (vcReference.ReferencedProject != null) { var referencedProject = vcReference.ReferencedProject as Project; var childProjectPath = referencedProject.FileName; var projectRestoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(projectRestoreReference); } else { hasMissingReferences = true; } } } catch (Exception ex) { hasMissingReferences = true; logger.LogDebug(ex.ToString()); } } if (hasMissingReferences) { // Log a generic message once per project if any items could not be resolved. var message = string.Format( CultureInfo.CurrentCulture, Strings.UnresolvedItemDuringProjectClosureWalk, _vsProjectAdapter.UniqueName); logger.LogVerbose(message); } return(results); }
static void ApplyIncludeFlags( ProjectRestoreReference dependency, string includeAssets, string excludeAssets, string privateAssets) { dependency.IncludeAssets = GetIncludeFlags(includeAssets, LibraryIncludeFlags.All); dependency.ExcludeAssets = GetIncludeFlags(excludeAssets, LibraryIncludeFlags.None); dependency.PrivateAssets = GetIncludeFlags(privateAssets, LibraryIncludeFlagUtils.DefaultSuppressParent); }
private static void AssertHashCode(bool expected, ProjectRestoreReference leftSide, ProjectRestoreReference rightSide) { if (expected) { leftSide.GetHashCode().Should().Be(rightSide.GetHashCode()); } else { leftSide.GetHashCode().Should().NotBe(rightSide.GetHashCode()); } }
private static void AssertEquality(bool expected, ProjectRestoreReference leftSide, ProjectRestoreReference rightSide) { if (expected) { leftSide.Should().Be(rightSide); } else { leftSide.Should().NotBe(rightSide); } }
public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync( Common.ILogger logger, CancellationToken _) { var unconfiguredProject = await _unconfiguredProject.GetValueAsync(); IBuildDependencyProjectReferencesService service = await GetProjectReferencesService(unconfiguredProject); if (service == null) { return(Enumerable.Empty <ProjectRestoreReference>()); } var results = new List <ProjectRestoreReference>(); var hasMissingReferences = false; foreach (IUnresolvedBuildDependencyProjectReference projectReference in await service.GetUnresolvedReferencesAsync()) { try { if (await projectReference.GetReferenceOutputAssemblyAsync()) { string childProjectPath = projectReference.EvaluatedIncludeAsFullPath; var projectRestoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(projectRestoreReference); } } catch (Exception ex) { hasMissingReferences = true; logger.LogDebug(ex.ToString()); } } if (hasMissingReferences) { // Log a generic message once per project if any items could not be resolved. // In most cases this can be ignored, but in the rare case where the unresolved // item is actually a project the restore result will be incomplete. var message = string.Format( CultureInfo.CurrentCulture, Strings.UnresolvedItemDuringProjectClosureWalk, _vsProjectAdapter.UniqueName); logger.LogVerbose(message); } return(results); }
private static Tuple <List <NuGetFramework>, ProjectRestoreReference> GetProjectRestoreReference(IMSBuildItem item) { var frameworks = GetFrameworks(item).ToList(); var reference = new ProjectRestoreReference() { ProjectPath = item.GetProperty("ProjectPath"), ProjectUniqueName = item.GetProperty("ProjectReferenceUniqueName"), }; ApplyIncludeFlags(reference, item.GetProperty("IncludeAssets"), item.GetProperty("ExcludeAssets"), item.GetProperty("PrivateAssets")); return(new Tuple <List <NuGetFramework>, ProjectRestoreReference>(frameworks, reference)); }
public void Equals_WithProjectUniqueName(string left, string right, bool expected) { var leftSide = new ProjectRestoreReference() { ProjectUniqueName = left }; var rightSide = new ProjectRestoreReference() { ProjectUniqueName = right }; AssertEquality(expected, leftSide, rightSide); }
private static ProjectRestoreReference ToProjectRestoreReference(LegacyCSProjProjectReference item) { var reference = new ProjectRestoreReference() { ProjectUniqueName = item.UniqueName, ProjectPath = item.UniqueName }; MSBuildRestoreUtility.ApplyIncludeFlags( reference, GetProjectMetadataValue(item, _includeAssets), GetProjectMetadataValue(item, _excludeAssets), GetProjectMetadataValue(item, _privateAssets)); return(reference); }
private static ProjectRestoreReference ToProjectRestoreReference(ProjectReference item) { var reference = new ProjectRestoreReference { ProjectUniqueName = item.UniqueName, ProjectPath = item.UniqueName }; MSBuildRestoreUtility.ApplyIncludeFlags( reference, GetReferenceMetadataValue(item, ProjectItemProperties.IncludeAssets), GetReferenceMetadataValue(item, ProjectItemProperties.ExcludeAssets), GetReferenceMetadataValue(item, ProjectItemProperties.PrivateAssets)); return(reference); }
public void HashCode_WithProjectUniqueName(string left, string right, bool expected) { var leftSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = left }; var rightSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = right }; AssertHashCode(expected, leftSide, rightSide); }
public void Equals_WithExcludeAssets(LibraryIncludeFlags left, LibraryIncludeFlags right, bool expected) { var leftSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = "path", ExcludeAssets = left }; var rightSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = "path", ExcludeAssets = right }; AssertEquality(expected, leftSide, rightSide); }
public void ProjectRestoreReferenceCloneTest() { // Set up var originalProjectRestoreReference = new ProjectRestoreReference(); originalProjectRestoreReference.ProjectPath = "Path"; originalProjectRestoreReference.ProjectUniqueName = "ProjectUniqueName"; originalProjectRestoreReference.IncludeAssets = LibraryModel.LibraryIncludeFlags.All; originalProjectRestoreReference.ExcludeAssets = LibraryModel.LibraryIncludeFlags.Analyzers; originalProjectRestoreReference.PrivateAssets = LibraryModel.LibraryIncludeFlags.Build; // Act var clone = originalProjectRestoreReference.Clone(); // Assert Assert.Equal(originalProjectRestoreReference, clone); Assert.False(object.ReferenceEquals(originalProjectRestoreReference, clone)); }
public void HashCode_WithPrivateAssets(LibraryIncludeFlags left, LibraryIncludeFlags right, bool expected) { var leftSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = "path", PrivateAssets = left }; var rightSide = new ProjectRestoreReference() { ProjectPath = "path", ProjectUniqueName = "path", PrivateAssets = right }; AssertHashCode(expected, leftSide, rightSide); }
private static ProjectRestoreMetadataFrameworkInfo CreateProjectRestoreMetadataFrameworkInfo(string frameworkName = "net461", string alias = "net461") { var projectReference = new ProjectRestoreReference(); projectReference.ProjectPath = "Path"; projectReference.ProjectUniqueName = "ProjectUniqueName"; projectReference.IncludeAssets = LibraryIncludeFlags.All; projectReference.ExcludeAssets = LibraryIncludeFlags.Analyzers; projectReference.PrivateAssets = LibraryIncludeFlags.Build; var nugetFramework = NuGetFramework.Parse(frameworkName); var originalPRMFI = new ProjectRestoreMetadataFrameworkInfo(nugetFramework); originalPRMFI.TargetAlias = alias ?? Guid.NewGuid().ToString(); originalPRMFI.ProjectReferences = new List <ProjectRestoreReference>() { projectReference }; return(originalPRMFI); }
private static ProjectRestoreReference ToProjectRestoreReference(MSBuildProjectItemData item, string projectDirectory) { var referencePath = Path.GetFullPath( Path.Combine( projectDirectory, item.EvaluatedInclude)); var reference = new ProjectRestoreReference() { ProjectUniqueName = referencePath, ProjectPath = referencePath }; MSBuildRestoreUtility.ApplyIncludeFlags( reference, includeAssets: GetPropertyValueOrDefault(item, IncludeAssets), excludeAssets: GetPropertyValueOrDefault(item, ExcludeAssets), privateAssets: GetPropertyValueOrDefault(item, PrivateAssets)); return(reference); }
private static ProjectRestoreReference ToProjectRestoreReference(IVsReferenceItem item, string projectDirectory) { // The path may be a relative path, to match the project unique name as a // string this should be the full path to the project // Remove ../../ and any other relative parts of the path that were used in the project file var referencePath = Path.GetFullPath(Path.Combine(projectDirectory, item.Name)); var dependency = new ProjectRestoreReference { ProjectPath = referencePath, ProjectUniqueName = referencePath, }; MSBuildRestoreUtility.ApplyIncludeFlags( dependency, includeAssets: GetPropertyValueOrNull(item, ProjectBuildProperties.IncludeAssets), excludeAssets: GetPropertyValueOrNull(item, ProjectBuildProperties.ExcludeAssets), privateAssets: GetPropertyValueOrNull(item, ProjectBuildProperties.PrivateAssets)); return(dependency); }
private static async Task AddProjectReferencesAsync( IDeferredProjectWorkspaceService deferredWorkspaceService, ProjectRestoreMetadata metadata, string projectPath) { var references = await deferredWorkspaceService.GetProjectReferencesAsync(projectPath); foreach (var reference in references) { var restoreReference = new ProjectRestoreReference() { ProjectPath = reference, ProjectUniqueName = reference }; foreach (var frameworkInfo in metadata.TargetFrameworks) { frameworkInfo.ProjectReferences.Add(restoreReference); } } }
private ProjectRestoreMetadata CreateProjectRestoreMetadata() { var projectReference = new ProjectRestoreReference(); projectReference.ProjectPath = "Path"; projectReference.ProjectUniqueName = "ProjectUniqueName"; projectReference.IncludeAssets = LibraryIncludeFlags.All; projectReference.ExcludeAssets = LibraryIncludeFlags.Analyzers; projectReference.PrivateAssets = LibraryIncludeFlags.Build; var nugetFramework = NuGetFramework.Parse("net461"); var originalPRMFI = new ProjectRestoreMetadataFrameworkInfo(nugetFramework); originalPRMFI.ProjectReferences = new List <ProjectRestoreReference>() { projectReference }; var targetframeworks = new List <ProjectRestoreMetadataFrameworkInfo>() { originalPRMFI }; var allWarningsAsErrors = true; var noWarn = new HashSet <NuGetLogCode>() { NuGetLogCode.NU1000, NuGetLogCode.NU1500 }; var warningsAsErrors = new HashSet <NuGetLogCode>() { NuGetLogCode.NU1001, NuGetLogCode.NU1501 }; var warningProperties = new WarningProperties(allWarningsAsErrors: allWarningsAsErrors, warningsAsErrors: warningsAsErrors, noWarn: noWarn); var originalProjectRestoreMetadata = new ProjectRestoreMetadata(); originalProjectRestoreMetadata.ProjectStyle = ProjectStyle.PackageReference; originalProjectRestoreMetadata.ProjectPath = "ProjectPath"; originalProjectRestoreMetadata.ProjectJsonPath = "ProjectJsonPath"; originalProjectRestoreMetadata.OutputPath = "OutputPath"; originalProjectRestoreMetadata.ProjectName = "ProjectName"; originalProjectRestoreMetadata.ProjectUniqueName = "ProjectUniqueName"; originalProjectRestoreMetadata.PackagesPath = "PackagesPath"; originalProjectRestoreMetadata.CacheFilePath = "CacheFilePath"; originalProjectRestoreMetadata.CrossTargeting = true; originalProjectRestoreMetadata.LegacyPackagesDirectory = true; originalProjectRestoreMetadata.ValidateRuntimeAssets = true; originalProjectRestoreMetadata.SkipContentFileWrite = true; originalProjectRestoreMetadata.TargetFrameworks = targetframeworks; originalProjectRestoreMetadata.Sources = new List <PackageSource>() { new PackageSource("http://api.nuget.org/v3/index.json") };; originalProjectRestoreMetadata.FallbackFolders = new List <string>() { "fallback1" }; originalProjectRestoreMetadata.ConfigFilePaths = new List <string>() { "config1" }; originalProjectRestoreMetadata.OriginalTargetFrameworks = new List <string>() { "net45" }; originalProjectRestoreMetadata.Files = new List <ProjectRestoreMetadataFile>() { new ProjectRestoreMetadataFile("packagePath", "absolutePath") }; originalProjectRestoreMetadata.ProjectWideWarningProperties = warningProperties; return(originalProjectRestoreMetadata); }
public void DependencyGraphSpec_RoundTripMSBuildMetadata_ProjectReferenceFlags() { // Arrange var frameworks = new List <TargetFrameworkInformation>(); frameworks.Add(new TargetFrameworkInformation() { FrameworkName = NuGetFramework.Parse("net45") }); var spec = new PackageSpec(frameworks); var msbuildMetadata = new ProjectRestoreMetadata(); spec.RestoreMetadata = msbuildMetadata; msbuildMetadata.ProjectUniqueName = "A55205E7-4D08-4672-8011-0925467CC45F"; msbuildMetadata.ProjectPath = "c:\\x\\x.csproj"; msbuildMetadata.ProjectName = PackageSpecName; msbuildMetadata.ProjectStyle = ProjectStyle.PackageReference; var tfmGroup = new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("net45")); var tfmGroup2 = new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("netstandard1.3")); msbuildMetadata.TargetFrameworks.Add(tfmGroup); msbuildMetadata.TargetFrameworks.Add(tfmGroup2); var ref1 = new ProjectRestoreReference() { ProjectUniqueName = "44B29B8D-8413-42D2-8DF4-72225659619B", ProjectPath = "c:\\a\\a.csproj", IncludeAssets = LibraryIncludeFlags.Build, ExcludeAssets = LibraryIncludeFlags.Compile, PrivateAssets = LibraryIncludeFlags.Runtime }; var ref2 = new ProjectRestoreReference() { ProjectUniqueName = "78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F", ProjectPath = "c:\\b\\b.csproj" }; tfmGroup.ProjectReferences.Add(ref1); tfmGroup.ProjectReferences.Add(ref2); tfmGroup2.ProjectReferences.Add(ref1); tfmGroup2.ProjectReferences.Add(ref2); // Act PackageSpec readSpec = PackageSpecTestUtility.RoundTrip(spec, PackageSpecName, PackageSpecPath); // Assert Assert.Equal(2, readSpec.RestoreMetadata.TargetFrameworks.Count); foreach (var framework in readSpec.RestoreMetadata.TargetFrameworks) { var references = framework.ProjectReferences.OrderBy(e => e.ProjectUniqueName).ToArray(); Assert.Equal("44B29B8D-8413-42D2-8DF4-72225659619B", references[0].ProjectUniqueName); Assert.Equal(LibraryIncludeFlags.Build, references[0].IncludeAssets); Assert.Equal(LibraryIncludeFlags.Compile, references[0].ExcludeAssets); Assert.Equal(LibraryIncludeFlags.Runtime, references[0].PrivateAssets); Assert.Equal("78A6AD3F-9FA5-47F6-A54E-84B46A48CB2F", references[1].ProjectUniqueName); Assert.Equal(LibraryIncludeFlags.All, references[1].IncludeAssets); Assert.Equal(LibraryIncludeFlags.None, references[1].ExcludeAssets); Assert.Equal(LibraryIncludeFlagUtils.DefaultSuppressParent, references[1].PrivateAssets); } }
internal IEnumerable <ProjectRestoreReference> GetProjectReferences(ILogger logger) { var results = new List <ProjectRestoreReference> (); // Verify ReferenceOutputAssembly var excludedProjects = GetExcludedReferences(project); bool hasMissingReferences = false; // find all references in the project foreach (var childReference in project.References) { try { if (childReference.ReferenceType != ReferenceType.Project) { continue; } if (!childReference.IsValid) { // Skip missing references and show a warning hasMissingReferences = true; continue; } // Skip missing references var sourceProject = childReference.ResolveProject(project.ParentSolution) as DotNetProject; // Skip missing references if (sourceProject != null) { string childProjectPath = sourceProject.FileName; // Skip projects which have ReferenceOutputAssembly=false if (!string.IsNullOrEmpty(childProjectPath) && !excludedProjects.Contains(childProjectPath, StringComparer.OrdinalIgnoreCase)) { var restoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(restoreReference); } } } catch (Exception ex) { // Exceptions are expected in some scenarios for native projects, // ignore them and show a warning hasMissingReferences = true; logger.LogDebug(ex.ToString()); LoggingService.LogError("Unable to find project dependencies.", ex); } } if (hasMissingReferences) { // Log a warning message once per project // This warning contains only the names of the root project and the project with the // broken reference. Attempting to display more details on the actual reference // that has the problem may lead to another exception being thrown. var warning = GettextCatalog.GetString( "Failed to resolve all project references. The package restore result for '{0}' or a dependant project may be incomplete.", project.Name); logger.LogWarning(warning); } return(results); }
private ProjectRestoreMetadata CreateProjectRestoreMetadata() { var projectReference = new ProjectRestoreReference { ProjectPath = "Path", ProjectUniqueName = "ProjectUniqueName", IncludeAssets = LibraryIncludeFlags.All, ExcludeAssets = LibraryIncludeFlags.Analyzers, PrivateAssets = LibraryIncludeFlags.Build }; var nugetFramework = NuGetFramework.Parse("net461"); var originalPRMFI = new ProjectRestoreMetadataFrameworkInfo(nugetFramework) { ProjectReferences = new List <ProjectRestoreReference>() { projectReference } }; var targetframeworks = new List <ProjectRestoreMetadataFrameworkInfo>() { originalPRMFI }; var allWarningsAsErrors = true; var noWarn = new HashSet <NuGetLogCode>() { NuGetLogCode.NU1000, NuGetLogCode.NU1500 }; var warningsAsErrors = new HashSet <NuGetLogCode>() { NuGetLogCode.NU1001, NuGetLogCode.NU1501 }; var warningProperties = new WarningProperties(allWarningsAsErrors: allWarningsAsErrors, warningsAsErrors: warningsAsErrors, noWarn: noWarn); var restoreLockProperties = new RestoreLockProperties(restorePackagesWithLockFile: "true", nuGetLockFilePath: null, restoreLockedMode: false); var originalProjectRestoreMetadata = new ProjectRestoreMetadata { ProjectStyle = ProjectStyle.PackageReference, ProjectPath = "ProjectPath", ProjectJsonPath = "ProjectJsonPath", OutputPath = "OutputPath", ProjectName = "ProjectName", ProjectUniqueName = "ProjectUniqueName", PackagesPath = "PackagesPath", CacheFilePath = "CacheFilePath", CrossTargeting = true, LegacyPackagesDirectory = true, ValidateRuntimeAssets = true, SkipContentFileWrite = true, TargetFrameworks = targetframeworks, Sources = new List <PackageSource>() { new PackageSource("http://api.nuget.org/v3/index.json") }, FallbackFolders = new List <string>() { "fallback1" }, ConfigFilePaths = new List <string>() { "config1" }, OriginalTargetFrameworks = new List <string>() { "net45" }, Files = new List <ProjectRestoreMetadataFile>() { new ProjectRestoreMetadataFile("packagePath", "absolutePath") }, ProjectWideWarningProperties = warningProperties, RestoreLockProperties = restoreLockProperties }; return(originalProjectRestoreMetadata); }
/// <summary> /// Get only the direct dependencies from a project /// </summary> public static async Task <IReadOnlyList <ProjectRestoreReference> > GetDirectProjectReferences( EnvDTEProject project, IEnumerable <string> resolvedProjects, ILogger log) { return(await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() => { // DTE calls need to be done from the main thread await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var results = new List <ProjectRestoreReference>(); var itemsFactory = ServiceLocator.GetInstance <IVsEnumHierarchyItemsFactory>(); // Verify ReferenceOutputAssembly var excludedProjects = GetExcludedReferences(project, itemsFactory); var hasMissingReferences = false; // find all references in the project foreach (var childReference in GetProjectReferences(project)) { try { var reference3 = childReference as Reference3; // check if deferred projects resolved this reference, which means this is still not loaded so simply continue // We'll get this reference from deferred projects later if (reference3 != null && resolvedProjects.Contains(reference3.Name, StringComparer.OrdinalIgnoreCase)) { continue; } // Set missing reference if // 1. reference is null OR // 2. reference is not resolved which means project is not loaded or assembly not found. else if (reference3 == null || !reference3.Resolved) { // Skip missing references and show a warning hasMissingReferences = true; continue; } // Skip missing references if (childReference.SourceProject != null) { if (EnvDTEProjectUtility.HasUnsupportedProjectCapability(childReference.SourceProject)) { // Skip this shared project continue; } var childProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(childReference.SourceProject); // Skip projects which have ReferenceOutputAssembly=false if (!string.IsNullOrEmpty(childProjectPath) && !excludedProjects.Contains(childProjectPath, StringComparer.OrdinalIgnoreCase)) { var restoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(restoreReference); } } } catch (Exception ex) { // Exceptions are expected in some scenarios for native projects, // ignore them and show a warning hasMissingReferences = true; log.LogDebug(ex.ToString()); Debug.Fail("Unable to find project dependencies: " + ex.ToString()); } } if (hasMissingReferences) { // Log a generic message once per project if any items could not be resolved. // In most cases this can be ignored, but in the rare case where the unresolved // item is actually a project the restore result will be incomplete. var message = string.Format( CultureInfo.CurrentCulture, Strings.UnresolvedItemDuringProjectClosureWalk, EnvDTEProjectInfoUtility.GetUniqueName(project)); log.LogVerbose(message); } return results; })); }
public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync( Common.ILogger logger, CancellationToken _) { // DTE calls need to be done from the main thread await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var results = new List <ProjectRestoreReference>(); var itemsFactory = ServiceLocator.GetInstance <IVsEnumHierarchyItemsFactory>(); // Verify ReferenceOutputAssembly var excludedProjects = GetExcludedReferences(itemsFactory, logger); var hasMissingReferences = false; // find all references in the project foreach (var childReference in GetVSProjectReferences()) { try { var reference3 = childReference as Reference3; // Verify that this is a project reference if (IsProjectReference(reference3, logger)) { // Verify that this is a valid and resolved project reference if (!IsReferenceResolved(reference3, logger)) { hasMissingReferences = true; continue; } if (EnvDTEProjectUtility.HasUnsupportedProjectCapability(reference3.SourceProject)) { // Skip this shared project continue; } var childProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(reference3.SourceProject); // Skip projects which have ReferenceOutputAssembly=false if (!string.IsNullOrEmpty(childProjectPath) && !excludedProjects.Contains(childProjectPath, StringComparer.OrdinalIgnoreCase)) { var restoreReference = new ProjectRestoreReference() { ProjectPath = childProjectPath, ProjectUniqueName = childProjectPath }; results.Add(restoreReference); } } else { hasMissingReferences = true; } } catch (Exception ex) { // Exceptions are expected in some scenarios for native projects, // ignore them and show a warning hasMissingReferences = true; logger.LogDebug(ex.ToString()); Debug.Fail("Unable to find project dependencies: " + ex.ToString()); } } if (hasMissingReferences) { // Log a generic message once per project if any items could not be resolved. // In most cases this can be ignored, but in the rare case where the unresolved // item is actually a project the restore result will be incomplete. var message = string.Format( CultureInfo.CurrentCulture, Strings.UnresolvedItemDuringProjectClosureWalk, _vsProjectAdapter.UniqueName); logger.LogVerbose(message); } return(results); }