From 2b5209d6b1497623f3300216af29cacbd7a9c87b Mon Sep 17 00:00:00 2001 From: Matt Warren Date: Mon, 13 Jun 2016 14:32:30 -0700 Subject: [PATCH] Add option to disable converting metadata to project references --- .../Options/InternalFeatureOnOffOptions.cs | 3 ++ .../ProjectSystem/AbstractProject.cs | 47 +++++++++++++------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs index 14096104472..5df390a59b5 100644 --- a/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs @@ -68,5 +68,8 @@ internal static class InternalFeatureOnOffOptions [ExportOption] public static readonly Option FullSolutionAnalysisMemoryMonitor = new Option(OptionName, "Full Solution Analysis Memory Monitor", defaultValue: true); + + [ExportOption] + public static readonly Option ProjectReferenceConversion = new Option(OptionName, "Project Reference Conversion", defaultValue: true); } } diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/AbstractProject.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/AbstractProject.cs index aa429d97f38..f918a526e92 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/AbstractProject.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/AbstractProject.cs @@ -9,6 +9,7 @@ using System.Windows.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Notification; @@ -483,11 +484,26 @@ protected void SetOptions(CompilationOptions compilationOptions, ParseOptions pa } } + protected bool CanConvertToProjectReferences + { + get + { + if (this.Workspace != null) + { + return this.Workspace.Options.GetOption(InternalFeatureOnOffOptions.ProjectReferenceConversion); + } + else + { + return InternalFeatureOnOffOptions.ProjectReferenceConversion.DefaultValue; + } + } + } + protected int AddMetadataReferenceAndTryConvertingToProjectReferenceIfPossible(string filePath, MetadataReferenceProperties properties) { // If this file is coming from a project, then we should convert it to a project reference instead AbstractProject project; - if (ProjectTracker.TryGetProjectByBinPath(filePath, out project)) + if (this.CanConvertToProjectReferences && ProjectTracker.TryGetProjectByBinPath(filePath, out project)) { var projectReference = new ProjectReference(project.Id, properties.Aliases, properties.EmbedInteropTypes); if (CanAddProjectReference(projectReference)) @@ -1015,23 +1031,26 @@ public virtual void Disconnect() internal void TryProjectConversionForIntroducedOutputPath(string binPath, AbstractProject projectToReference) { - // We should not already have references for this, since we're only introducing the path for the first time - Contract.ThrowIfTrue(_metadataFileNameToConvertedProjectReference.ContainsKey(binPath)); - - var metadataReference = TryGetCurrentMetadataReference(binPath); - if (metadataReference != null) + if (this.CanConvertToProjectReferences) { - var projectReference = new ProjectReference( - projectToReference.Id, - metadataReference.Properties.Aliases, - metadataReference.Properties.EmbedInteropTypes); + // We should not already have references for this, since we're only introducing the path for the first time + Contract.ThrowIfTrue(_metadataFileNameToConvertedProjectReference.ContainsKey(binPath)); - if (CanAddProjectReference(projectReference)) + var metadataReference = TryGetCurrentMetadataReference(binPath); + if (metadataReference != null) { - RemoveMetadataReferenceCore(metadataReference, disposeReference: true); - AddProjectReference(projectReference); + var projectReference = new ProjectReference( + projectToReference.Id, + metadataReference.Properties.Aliases, + metadataReference.Properties.EmbedInteropTypes); + + if (CanAddProjectReference(projectReference)) + { + RemoveMetadataReferenceCore(metadataReference, disposeReference: true); + AddProjectReference(projectReference); - _metadataFileNameToConvertedProjectReference.Add(binPath, projectReference); + _metadataFileNameToConvertedProjectReference.Add(binPath, projectReference); + } } } } -- GitLab