Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle multiple reference aliases #1905

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ private void UpdateProjectReferences(Project project, ImmutableArray<string> pro
if (projectFileInfo.ProjectReferenceAliases.TryGetValue(projectReferencePath, out var projectReferenceAliases))
{
if (!string.IsNullOrEmpty(projectReferenceAliases))
{
aliases = projectReferenceAliases.Split(';').ToImmutableArray();
{
aliases = ImmutableArray.CreateRange(projectReferenceAliases.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries).Select(a => a.Trim()));
_logger.LogDebug($"Setting aliases: {projectReferencePath}, {projectReferenceAliases} ");
}
}
Expand Down Expand Up @@ -740,7 +740,7 @@ private void UpdateReferences(Project project, ImmutableArray<string> projectRef
{
if (!string.IsNullOrEmpty(aliases))
{
reference = reference.WithAliases(aliases.Split(';'));
reference = reference.WithAliases(aliases.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries).Select(a => a.Trim()));
_logger.LogDebug($"setting aliases: {referencePath}, {aliases} ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<Reference Include="ExternAlias.Lib">
<HintPath>$(ProjectDir)../ExternAlias.Lib/bin/$(Configuration)/netstandard2.0/ExternAlias.Lib.dll</HintPath>
<Aliases>abc</Aliases>
<Aliases>abc,def</Aliases>
</Reference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern alias abc;
extern alias def;
using System;

namespace ExternAlias.App
Expand All @@ -8,6 +9,7 @@ class Program
static void Main(string[] args)
{
new abc::ExternAlias.Lib.Class1();
new def::ExternAlias.Lib.Class1();
Console.WriteLine("Hello World!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<ProjectReference Include="../ExternAlias.Lib/ExternAlias.Lib.csproj">
<Aliases>abc</Aliases>
<Aliases>abc,def</Aliases>
</ProjectReference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern alias abc;
extern alias def;
using System;

namespace ExternAlias.App
Expand All @@ -8,6 +9,7 @@ class Program
static void Main(string[] args)
{
new abc::ExternAlias.Lib.Class1();
new def::ExternAlias.Lib.Class1();
Console.WriteLine("Hello World!");
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public async Task ExternAliasWithReference()

var libpath = Path.Combine(testProject.Directory, "ExternAlias.Lib", "bin", "Debug", "netstandard2.0", "ExternAlias.Lib.dll");
Assert.True(projectFileInfo.ReferenceAliases.ContainsKey(libpath));
Assert.Equal("abc", projectFileInfo.ReferenceAliases[libpath]);
Assert.Equal("abc,def", projectFileInfo.ReferenceAliases[libpath]);
}
}

Expand All @@ -179,7 +179,7 @@ public async Task ExternAliasWithProjectReference()

var projectReferencePath = Path.Combine(testProject.Directory, "ExternAlias.Lib", "ExternAlias.Lib.csproj");
Assert.True(projectFileInfo.ProjectReferenceAliases.ContainsKey(projectReferencePath));
Assert.Equal("abc", projectFileInfo.ProjectReferenceAliases[projectReferencePath]);
Assert.Equal("abc,def", projectFileInfo.ProjectReferenceAliases[projectReferencePath]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ public async Task TestProjectWithAliasOnProjectReference()
.ProjectReferences
.Single(x => x.ProjectId == lib.Id);

Assert.Equal("abc", projectReference.Aliases.Single());
Assert.Collection(projectReference.Aliases,
referenceA => Assert.Equal("abc",referenceA),
referenceB => Assert.Equal("def",referenceB));
}
}

Expand All @@ -337,7 +339,9 @@ public async Task TestProjectWithAliasOnReference()
.MetadataReferences
.Single(x => x.Display == "ExternAlias.Lib.dll");

Assert.Equal("abc", reference.Properties.Aliases.Single());
Assert.Collection(reference.Properties.Aliases,
referenceA => Assert.Equal("abc",referenceA),
referenceB => Assert.Equal("def",referenceB));
}
}
}
Expand Down