Skip to content

Commit

Permalink
Merge pull request #1195 from DustinCampbell/fix-referenced-multi-tfm…
Browse files Browse the repository at this point in the history
…-projects

Fix bug when multi-TFM project reference is outside OmniSharp's target path
  • Loading branch information
filipw authored May 21, 2018
2 parents 689cd9b + f929609 commit 10f3b5e
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"TwoProjectsWithSolution",
"ProjectWithGeneratedFile",
"CSharpAndFSharp",
"ProjectWithMismatchedFileName"
"ProjectWithMismatchedFileName",
"ProjectWithMultiTFMLib"
],
"LegacyTestAssets": [
"LegacyNUnitTestProject",
Expand Down
11 changes: 6 additions & 5 deletions src/OmniSharp.MSBuild/ProjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ private MSB.Evaluation.Project EvaluateProjectFileCore(string filePath)

toolsVersion = GetLegalToolsetVersion(toolsVersion, projectCollection.Toolsets);

return projectCollection.LoadProject(filePath, toolsVersion);
var project = projectCollection.LoadProject(filePath, toolsVersion);

SetTargetFrameworkIfNeeded(project);

return project;
}

private static void SetTargetFrameworkIfNeeded(MSB.Evaluation.Project evaluatedProject)
Expand All @@ -127,10 +131,7 @@ private static void SetTargetFrameworkIfNeeded(MSB.Evaluation.Project evaluatedP
// do better and potentially allow OmniSharp hosts to select a target framework.
targetFramework = targetFrameworks[0];
evaluatedProject.SetProperty(PropertyNames.TargetFramework, targetFramework);
}
else if (!string.IsNullOrWhiteSpace(targetFramework) && targetFrameworks.Length == 0)
{
targetFrameworks = ImmutableArray.Create(targetFramework);
evaluatedProject.ReevaluateIfNecessary();
}
}

Expand Down
12 changes: 12 additions & 0 deletions test-assets/test-projects/ProjectWithMultiTFMLib/App/App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\Lib\Lib.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions test-assets/test-projects/ProjectWithMultiTFMLib/App/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Lib
{
public class Class1
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "Lib\Lib.csproj", "{CE41561B-5D13-4688-8686-EEFF744BE8B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|x64.ActiveCfg = Debug|x64
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|x64.Build.0 = Debug|x64
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|x86.ActiveCfg = Debug|x86
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Debug|x86.Build.0 = Debug|x86
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|Any CPU.Build.0 = Release|Any CPU
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|x64.ActiveCfg = Release|x64
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|x64.Build.0 = Release|x64
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|x86.ActiveCfg = Release|x86
{632DFE45-B56E-4158-8F27-45E2BA0BAFCF}.Release|x86.Build.0 = Release|x86
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|x64.ActiveCfg = Debug|x64
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|x64.Build.0 = Debug|x64
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|x86.ActiveCfg = Debug|x86
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Debug|x86.Build.0 = Debug|x86
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|Any CPU.Build.0 = Release|Any CPU
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|x64.ActiveCfg = Release|x64
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|x64.Build.0 = Release|x64
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|x86.ActiveCfg = Release|x86
{CE41561B-5D13-4688-8686-EEFF744BE8B5}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,27 @@ public async Task TestProjectWithReferencedProjectOutsideOfOmniSharp()
}
}

[Fact]
public async Task TestProjectWithMultiTFMReferencedProjectOutsideOfOmniSharp()
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMultiTFMLib"))
using (var host = CreateOmniSharpHost(Path.Combine(testProject.Directory, "App")))
{
var workspaceInfo = await GetWorkspaceInfoAsync(host);

Assert.NotNull(workspaceInfo.Projects);
Assert.Equal(2, workspaceInfo.Projects.Count);

var project1 = workspaceInfo.Projects[0];
Assert.Equal("App.csproj", Path.GetFileName(project1.Path));

var project2 = workspaceInfo.Projects[1];
Assert.Equal("Lib.csproj", Path.GetFileName(project2.Path));
Assert.Equal(".NETStandard,Version=v1.3", project2.TargetFramework);
Assert.Equal(2, project2.TargetFrameworks.Count);
}
}

[ConditionalFact(typeof(WindowsOnly))]
public async Task AntlrGeneratedFiles()
{
Expand Down

0 comments on commit 10f3b5e

Please # to comment.