未验证 提交 e75f8da4 编写于 作者: M msftbot[bot] 提交者: GitHub

Merge pull request #45316 from jasonmalinowski/fix-project-references-to-web-projects

Don't fetch output paths for Intellisense projects
......@@ -24,9 +24,7 @@ public void BindToProject(ICSharpProjectRoot projectRoot, IVsHierarchy hierarchy
projectName,
hierarchy,
this.SystemServiceProvider,
this.Package.ComponentModel.GetService<IThreadingContext>(),
this.HostDiagnosticUpdateSource,
this.Workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService<ICommandLineParserService>());
this.Package.ComponentModel.GetService<IThreadingContext>());
projectRoot.SetProjectSite(project);
}
......
......@@ -6,13 +6,11 @@
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Legacy;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim
......@@ -51,17 +49,14 @@ private new OptionsProcessor VisualStudioProjectOptionsProcessor
string projectSystemName,
IVsHierarchy hierarchy,
IServiceProvider serviceProvider,
IThreadingContext threadingContext,
HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
ICommandLineParserService commandLineParserServiceOpt)
IThreadingContext threadingContext)
: base(projectSystemName,
hierarchy,
LanguageNames.CSharp,
isVsIntellisenseProject: projectRoot is IVsIntellisenseProject,
serviceProvider,
threadingContext,
externalErrorReportingPrefix: "CS",
hostDiagnosticUpdateSourceOpt: hostDiagnosticUpdateSourceOpt,
commandLineParserServiceOpt: commandLineParserServiceOpt)
externalErrorReportingPrefix: "CS")
{
_projectRoot = projectRoot;
_serviceProvider = serviceProvider;
......
......@@ -8,7 +8,6 @@
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.UnitTests;
using Microsoft.VisualStudio;
......@@ -39,9 +38,7 @@ public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment,
projectSystemName: projectName,
hierarchy: hierarchy,
serviceProvider: environment.ServiceProvider,
threadingContext: environment.ThreadingContext,
hostDiagnosticUpdateSourceOpt: null,
commandLineParserServiceOpt: new CSharpCommandLineParserService());
threadingContext: environment.ThreadingContext);
}
public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, params string[] commandLineArguments)
......
......@@ -9,10 +9,8 @@
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel;
using Microsoft.VisualStudio.LanguageServices.Implementation.EditAndContinue;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Microsoft.VisualStudio.Shell;
......@@ -42,6 +40,11 @@ internal abstract partial class AbstractLegacyProject : ForegroundThreadAffiniti
/// </summary>
private readonly string _projectDirectory = null;
/// <summary>
/// Whether we should ignore the output path for this project because it's a special project.
/// </summary>
private readonly bool _ignoreOutputPath;
private static readonly char[] PathSeparatorCharacters = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
#region Mutable fields that should only be used from the UI thread
......@@ -54,11 +57,10 @@ internal abstract partial class AbstractLegacyProject : ForegroundThreadAffiniti
string projectSystemName,
IVsHierarchy hierarchy,
string language,
bool isVsIntellisenseProject,
IServiceProvider serviceProvider,
IThreadingContext threadingContext,
string externalErrorReportingPrefix,
HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
ICommandLineParserService commandLineParserServiceOpt)
string externalErrorReportingPrefix)
: base(threadingContext, assertIsForeground: true)
{
Contract.ThrowIfNull(hierarchy);
......@@ -79,6 +81,23 @@ internal abstract partial class AbstractLegacyProject : ForegroundThreadAffiniti
_projectDirectory = Path.GetDirectoryName(projectFilePath);
}
if (isVsIntellisenseProject)
{
// IVsIntellisenseProjects are usually used for contained language cases, which means these projects don't have any real
// output path that we should consider. Since those point to the same IVsHierarchy as another project, we end up with two projects
// with the same output path, which potentially breaks conversion of metadata references to project references. However they're
// also used for database projects and a few other cases where there there isn't a "primary" IVsHierarchy.
// As a heuristic here we'll ignore the output path if we already have another project tied to the IVsHierarchy.
foreach (var projectId in Workspace.CurrentSolution.ProjectIds)
{
if (Workspace.GetHierarchy(projectId) == hierarchy)
{
_ignoreOutputPath = true;
break;
}
}
}
var projectFactory = componentModel.GetService<VisualStudioProjectFactory>();
VisualStudioProject = projectFactory.CreateAndAddToWorkspace(
projectSystemName,
......@@ -217,6 +236,15 @@ protected void RemoveFile(string filename)
protected void RefreshBinOutputPath()
{
// These projects are created against the same hierarchy as the "main" project that
// hosts the rest of the code; if we query the IVsHierarchy for the output path
// we'll end up with duplicate output paths which can break P2P referencing. Since the output
// path doesn't make sense for these, we'll ignore them.
if (_ignoreOutputPath)
{
return;
}
if (!(Hierarchy is IVsBuildPropertyStorage storage))
{
return;
......@@ -271,22 +299,6 @@ private static Guid GetProjectIDGuid(IVsHierarchy hierarchy)
return Guid.Empty;
}
private static bool GetIsWebsiteProject(IVsHierarchy hierarchy)
{
try
{
if (hierarchy.TryGetProject(out var project))
{
return project.Kind == VsWebSite.PrjKind.prjKindVenusProject;
}
}
catch (Exception)
{
}
return false;
}
/// <summary>
/// Map of folder item IDs in the workspace to the string version of their path.
/// </summary>
......
......@@ -3,7 +3,6 @@
' See the LICENSE file in the project root for more information.
Imports System.IO
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework
Imports Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
Imports Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim.Interop
......@@ -15,9 +14,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Vi
Return New VisualBasicProject(projectName,
If(compilerHost, MockCompilerHost.FullFrameworkCompilerHost),
environment.CreateHierarchy(projectName, projectBinPath, projectRefPath:=Nothing, "VB"),
isIntellisenseProject:=False,
environment.ServiceProvider,
environment.ThreadingContext,
commandLineParserServiceOpt:=New VisualBasicCommandLineParserService())
environment.ThreadingContext)
End Function
Public Function CreateMinimalCompilerOptions(project As VisualBasicProject) As VBCompilerOptions
......
......@@ -2,9 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.VisualStudio.LanguageServices.Implementation.TaskList
Imports Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
......@@ -27,10 +25,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic
wszName,
pVbCompilerHost,
pProjHier,
TypeOf punkProject Is IVsIntellisenseProject,
Me,
ComponentModel.GetService(Of IThreadingContext),
hostDiagnosticUpdateSource,
commandLineParserServiceOpt:=Workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService(Of ICommandLineParserService))
ComponentModel.GetService(Of IThreadingContext))
End Function
Public Function IsValidIdentifier(wszIdentifier As String) As Boolean Implements IVbCompiler.IsValidIdentifier
......
......@@ -39,12 +39,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
Friend Sub New(projectSystemName As String,
compilerHost As IVbCompilerHost,
hierarchy As IVsHierarchy,
isIntellisenseProject As Boolean,
serviceProvider As IServiceProvider,
threadingContext As IThreadingContext,
Optional hostDiagnosticUpdateSourceOpt As HostDiagnosticUpdateSource = Nothing,
Optional commandLineParserServiceOpt As ICommandLineParserService = Nothing)
MyBase.New(projectSystemName, hierarchy, LanguageNames.VisualBasic,
serviceProvider, threadingContext, "VB", hostDiagnosticUpdateSourceOpt, commandLineParserServiceOpt)
threadingContext As IThreadingContext)
MyBase.New(projectSystemName, hierarchy, LanguageNames.VisualBasic, isIntellisenseProject, serviceProvider, threadingContext, "VB")
_compilerHost = compilerHost
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册