提交 bb3ca607 编写于 作者: J Jason Malinowski

Pass the ref path to the project in the legacy projects case

Prior to 7e10f449 we had a hack which
worked around more proper project for fetching ref paths; when looking
for possible references to convert to project references, we just
stripped the ref subfolder off of a path and then compared that way.
The intent was then to fix up proper support by correctly fetching
the ref paths when that's available, but then we missed actually
fetching it in the legacy project system case.
上级 febb2437
......@@ -13,7 +13,6 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework;
......@@ -27,8 +26,13 @@ internal static class CSharpHelpers
public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment, string projectName)
{
var projectBinPath = Path.GetTempPath();
var hierarchy = environment.CreateHierarchy(projectName, projectBinPath, "CSharp");
var hierarchy = environment.CreateHierarchy(projectName, projectBinPath, projectRefPath: null, projectCapabilities: "CSharp");
return CreateCSharpProject(environment, projectName, hierarchy);
}
public static CSharpProjectShim CreateCSharpProject(TestEnvironment environment, string projectName, IVsHierarchy hierarchy)
{
return new CSharpProjectShim(
new MockCSharpProjectRoot(hierarchy),
projectSystemName: projectName,
......@@ -70,14 +74,14 @@ public static unsafe void SetOption(this CSharpProjectShim csharpProject, Compil
public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, string projectName, string projectFilePath, string binOutputPath, Guid projectGuid, params string[] commandLineArguments)
{
var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "CSharp");
var hierarchy = environment.CreateHierarchy(projectName, binOutputPath, projectRefPath: null, "CSharp");
var cpsProjectFactory = environment.ExportProvider.GetExportedValue<IWorkspaceProjectContextFactory>();
var cpsProject = (CPSProject)cpsProjectFactory.CreateProjectContext(
LanguageNames.CSharp,
projectName,
projectFilePath,
projectGuid,
hierarchy,
hierarchy,
binOutputPath);
var commandLineForOptions = string.Join(" ", commandLineArguments);
......@@ -88,7 +92,7 @@ public static CPSProject CreateCSharpCPSProject(TestEnvironment environment, str
public static CPSProject CreateNonCompilableProject(TestEnvironment environment, string projectName, string projectFilePath)
{
var hierarchy = environment.CreateHierarchy(projectName, projectFilePath, "");
var hierarchy = environment.CreateHierarchy(projectName, projectBinPath: null, projectRefPath: null, "");
var cpsProjectFactory = environment.ExportProvider.GetExportedValue<IWorkspaceProjectContextFactory>();
return (CPSProject)cpsProjectFactory.CreateProjectContext(
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Windows.Controls;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework;
using Roslyn.Test.Utilities;
using Xunit;
namespace Roslyn.VisualStudio.CSharp.UnitTests.ProjectSystemShim.LegacyProject
{
[UseExportProvider]
public class OutputPathTests
{
[WpfTheory]
[Trait(Traits.Feature, Traits.Features.ProjectSystemShims)]
[InlineData(@"Z:\ref\WithRefPath.dll")]
[InlineData(null)]
public void RefPathPassedToWorkspace(string expectedRefPath)
{
using (var environment = new TestEnvironment())
{
var hierarchyWithRefPath =
environment.CreateHierarchy(
"WithRefPath",
@"Z:\WithRefPath.dll",
expectedRefPath,
"CSharp");
var project = CSharpHelpers.CreateCSharpProject(environment, "WithRefPath", hierarchyWithRefPath);
var workspaceProject = environment.Workspace.CurrentSolution.Projects.Single();
Assert.Equal(expectedRefPath, workspaceProject.OutputRefFilePath);
}
}
}
}
......@@ -242,6 +242,15 @@ protected void RefreshBinOutputPath()
}
VisualStudioProject.OutputFilePath = FileUtilities.NormalizeAbsolutePath(Path.Combine(outputDirectory, targetFileName));
if (ErrorHandler.Succeeded(storage.GetPropertyValue("TargetRefPath", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out var targetRefPath)) && !string.IsNullOrEmpty(targetRefPath))
{
VisualStudioProject.OutputRefFilePath = targetRefPath;
}
else
{
VisualStudioProject.OutputRefFilePath = null;
}
}
private static Guid GetProjectIDGuid(IVsHierarchy hierarchy)
......
......@@ -19,6 +19,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
Private _projectName As String
Private _projectBinPath As String
Private ReadOnly _projectRefPath As String
Private ReadOnly _projectCapabilities As String
Private ReadOnly _projectMock As Mock(Of EnvDTE.Project) = New Mock(Of EnvDTE.Project)(MockBehavior.Strict)
......@@ -28,9 +29,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
Public Sub New(projectName As String,
projectFilePath As String,
projectBinPath As String,
projectRefPath As String,
projectCapabilities As String)
_projectName = projectName
_projectBinPath = projectBinPath
_projectRefPath = projectRefPath
_projectCapabilities = projectCapabilities
_hierarchyItems.Add(CType(VSConstants.VSITEMID.Root, UInteger), projectFilePath)
End Sub
......@@ -324,9 +327,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
ElseIf pszPropName = "TargetFileName" Then
pbstrPropValue = PathUtilities.ChangeExtension(_projectName, "dll")
Return VSConstants.S_OK
ElseIf pszPropName = "TargetRefPath" Then
pbstrPropValue = _projectRefPath
Return VSConstants.S_OK
End If
Throw New NotImplementedException()
Throw New NotSupportedException($"{NameOf(MockHierarchy)}.{NameOf(GetPropertyValue)} does not support reading {pszPropName}.")
End Function
Public Function SetPropertyValue(pszPropName As String, pszConfigName As String, storage As UInteger, pszPropValue As String) As Integer Implements IVsBuildPropertyStorage.SetPropertyValue
......
......@@ -9,7 +9,6 @@ Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities
Imports Microsoft.CodeAnalysis.Editor.UnitTests
Imports Microsoft.CodeAnalysis.FindSymbols
Imports Microsoft.CodeAnalysis.Shared.TestHooks
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.VisualStudio.ComponentModelHost
Imports Microsoft.VisualStudio.Composition
......@@ -131,8 +130,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
Return result
End Function
Public Function CreateHierarchy(projectName As String, projectBinPath As String, projectCapabilities As String) As IVsHierarchy
Return New MockHierarchy(projectName, CreateProjectFile(projectName), projectBinPath, projectCapabilities)
Public Function CreateHierarchy(projectName As String, projectBinPath As String, projectRefPath As String, projectCapabilities As String) As IVsHierarchy
Return New MockHierarchy(projectName, CreateProjectFile(projectName), projectBinPath, projectRefPath, projectCapabilities)
End Function
Public Function GetUpdatedCompilationOptionOfSingleProject() As CompilationOptions
......
......@@ -12,7 +12,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Vi
Dim projectBinPath = Path.GetTempPath()
Return New VisualBasicProject(projectName,
If(compilerHost, MockCompilerHost.FullFrameworkCompilerHost),
environment.CreateHierarchy(projectName, projectBinPath, "VB"),
environment.CreateHierarchy(projectName, projectBinPath, projectRefPath:=Nothing, "VB"),
environment.ServiceProvider,
environment.ThreadingContext,
commandLineParserServiceOpt:=New VisualBasicCommandLineParserService())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册