-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Adding P2P test coverage for targeting common PCL profiles #1606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using static Microsoft.NET.TestFramework.Commands.MSBuildTest; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Xunit; | ||
using FluentAssertions; | ||
using System.Runtime.InteropServices; | ||
using System.Linq; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public class GivenThatWeWantToVerifyPCLProjectReferenceCompat : SdkTest | ||
{ | ||
public GivenThatWeWantToVerifyPCLProjectReferenceCompat(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("netstandard1.1", "Profile7", "v4.5", true, true)] | ||
[InlineData("netstandard1.0", "Profile31", "v4.6", true, true)] | ||
[InlineData("netstandard1.2", "Profile32", "v4.6", true, true)] | ||
[InlineData("netstandard1.2", "Profile44", "v4.6", true, true)] | ||
[InlineData("netstandard1.0", "Profile49", "v4.5", true, true)] | ||
[InlineData("netstandard1.0", "Profile78", "v4.5", true, true)] | ||
[InlineData("netstandard1.0", "Profile84", "v4.6", true, true)] | ||
[InlineData("netstandard1.1", "Profile111", "v4.5", true, true)] | ||
[InlineData("netstandard1.2", "Profile151", "v4.6", true, true)] | ||
[InlineData("netstandard1.0", "Profile157", "v4.6", true, true)] | ||
[InlineData("netstandard1.0", "Profile259", "v4.5", true, true)] | ||
|
||
public void PCL_Project_reference_compat(string referencerTarget, string profileDependencyTarget, string netDependencyTarget, | ||
bool restoreSucceeds, bool buildSucceeds) | ||
{ | ||
string identifier = "_TestID_" + referencerTarget + "_" + profileDependencyTarget; | ||
|
||
TestProject referencerProject = GetTestProject("Referencer", referencerTarget, null, true); | ||
TestProject dependencyProject = GetTestProject("Dependency", netDependencyTarget, profileDependencyTarget, false); | ||
referencerProject.ReferencedProjects.Add(dependencyProject); | ||
|
||
// Set the referencer project as an Exe unless it targets .NET Standard | ||
if (!referencerProject.ShortTargetFrameworkIdentifiers.Contains("netstandard")) | ||
{ | ||
referencerProject.IsExe = true; | ||
} | ||
|
||
// Skip running test if not running on Windows | ||
// https://github.com/dotnet/sdk/issues/335 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect these tests wouldn't work on .NET Core msbuild because the deployment doesn't carry the PCL targets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now that even core msbuild can build these projects in the test environment because we force a VS Dev command prompt which sets VSINSTALLDIR and core msbuild is "crossing the streams" into VS land to pick up these targets. Since we already require a VS command prompt for building/testing SDK (there's an error from build.cmd otherwise currently), I suppose this is OK. |
||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
if (!referencerProject.BuildsOnNonWindows || !dependencyProject.BuildsOnNonWindows) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
var testAsset = _testAssetsManager.CreateTestProject(referencerProject, nameof(PCL_Project_reference_compat), identifier); | ||
|
||
var restoreCommand = testAsset.GetRestoreCommand(Log, relativePath: "Referencer"); | ||
|
||
if (restoreSucceeds) | ||
{ | ||
restoreCommand.Execute().Should().Pass(); | ||
} | ||
else | ||
{ | ||
restoreCommand.Execute().Should().Fail(); | ||
} | ||
|
||
var appProjectDirectory = Path.Combine(testAsset.TestRoot, "Referencer"); | ||
var buildCommand = new BuildCommand(Log, appProjectDirectory); | ||
var result = buildCommand.Execute(); | ||
|
||
if (buildSucceeds) | ||
{ | ||
result.Should().Pass(); | ||
} | ||
else | ||
{ | ||
result.Should().Fail() | ||
.And.HaveStdOutContaining("It cannot be referenced by a project that targets"); | ||
} | ||
} | ||
|
||
TestProject GetTestProject(string name, string target, string profile, bool isSdkProject) | ||
{ | ||
TestProject ret = new TestProject() | ||
{ | ||
Name = name, | ||
IsSdkProject = isSdkProject | ||
}; | ||
|
||
if (isSdkProject) | ||
{ | ||
ret.TargetFrameworks = target; | ||
} | ||
else | ||
{ | ||
ret.TargetFrameworkVersion = target; | ||
if (!string.IsNullOrEmpty(profile)) | ||
{ | ||
ret.TargetFrameworkProfile = profile; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,12 @@ public class TestProject | |
public string RuntimeFrameworkVersion { get; set; } | ||
|
||
public string RuntimeIdentifier { get; set; } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unecessary whitespace diff |
||
// TargetFrameworkVersion applies to non-SDK projects | ||
public string TargetFrameworkVersion { get; set; } | ||
|
||
public string TargetFrameworkProfile { get; set; } | ||
|
||
public List<TestProject> ReferencedProjects { get; } = new List<TestProject>(); | ||
|
||
public List<string> References { get; } = new List<string>(); | ||
|
@@ -161,8 +163,17 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder) | |
} | ||
else | ||
{ | ||
var targetFrameworkVersionElement = propertyGroup.Element(ns + "TargetFrameworkVersion"); | ||
targetFrameworkVersionElement.SetValue(this.TargetFrameworkVersion); | ||
if (!string.IsNullOrEmpty(this.TargetFrameworkProfile)) | ||
{ | ||
propertyGroup.Add(new XElement(ns + "TargetFrameworkProfile", this.TargetFrameworkProfile)); | ||
|
||
// To construct an accurate PCL project file, we must modify the import of the CSharp targets; | ||
// building/testing the SDK requires a VSDev command prompt which sets 'VSINSTALLDIR' | ||
var importGroup = projectXml.Root.Elements(ns + "Import").Last(); | ||
importGroup.Attribute("Project").Value = "$(VSINSTALLDIR)\\MSBuild\\Microsoft\\Portable\\$(TargetFrameworkVersion)\\Microsoft.Portable.CSharp.targets"; | ||
} | ||
|
||
propertyGroup.Element(ns + "TargetFrameworkVersion").SetValue(this.TargetFrameworkVersion); | ||
} | ||
|
||
foreach (var additionalProperty in AdditionalProperties) | ||
|
@@ -290,7 +301,11 @@ public override string ToString() | |
{ | ||
ret.Append(TargetFrameworks); | ||
} | ||
if (!string.IsNullOrEmpty(TargetFrameworkVersion)) | ||
if (!string.IsNullOrEmpty(TargetFrameworkProfile)) | ||
{ | ||
ret.Append(TargetFrameworkProfile); | ||
} | ||
else if (!string.IsNullOrEmpty(TargetFrameworkVersion)) | ||
{ | ||
ret.Append(TargetFrameworkVersion); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the bools are for if they are always true,true.
We should probably also add cases that we expect to fail.