Skip to content

Commit

Permalink
Correctly handle multiple reference aliases (#1905)
Browse files Browse the repository at this point in the history
* Correctly handle multiple reference aliases

* Simplify splitting and trimming
  • Loading branch information
laenas authored Aug 21, 2020
1 parent ec1a442 commit 33a747e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
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

0 comments on commit 33a747e

Please sign in to comment.