fix: share ProjectCollection instance and implement IDisposable - #69
Closed
mfogliatto wants to merge 1 commit into
Closed
fix: share ProjectCollection instance and implement IDisposable#69mfogliatto wants to merge 1 commit into
mfogliatto wants to merge 1 commit into
Conversation
Refactor MSBuildProjectMetadataProvider to use a single ProjectCollection instance across both GetProjectReferences() and GetPropertyValue(), eliminating redundant project loads when both methods are called for the same project file. Changes: - MSBuildProjectMetadataProvider now holds a shared ProjectCollection created once in the constructor - Added LoadOrGetProject() helper that caches loaded projects via ProjectCollection.GetLoadedProjects(), avoiding double evaluation - Implemented IDisposable with proper dispose pattern to clean up the ProjectCollection (UnloadAllProjects + Dispose) - ReferenceCopTask.Execute() now disposes the provider in a finally block using safe cast (as IDisposable)?.Dispose() Fixes #68
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #68 — eliminates redundant
ProjectCollectioninstances and project loads, and properly disposes theIDisposableresource.Problem
MSBuildProjectMetadataProviderwas creating a newProjectCollectionand callingLoadProject()in bothGetProjectReferences()andGetPropertyValue(). SinceReferenceCopTask.Execute()calls both methods for the same project file, this caused:ProjectCollectionimplementsIDisposablebut was never disposed, leaking unmanaged resources (COM interop, file handles)Changes
MSBuildProjectMetadataProvider.csProjectCollectioncreated in the constructorLoadOrGetProject()helper that checksProjectCollection.GetLoadedProjects()before loading, so the project is only parsed once even when both methods are calledIDisposablewith proper dispose pattern (UnloadAllProjects()+Dispose()on the collection)ReferenceCopTask.csExecute()now disposes the provider in afinallyblock via safe cast:(this.projectReferencesProvider as IDisposable)?.Dispose()IDisposableImpact
ProjectCollectioninstances