diff --git a/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs index 14096104472176c0395b828f495e7c9c9f73ee06..5df390a59b571aaf096dcc357c27387c1ef818d3 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 aa429d97f3884bc2861ab5bb2f3b96daeec1700e..f918a526e92310f62f53a4b0dc86820e8cf8061d 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); + } } } }