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

Ensure Microsoft.NETCore.App is an implicit dependency for publish. #2881

Merged
merged 2 commits into from
Feb 13, 2019
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
13 changes: 13 additions & 0 deletions src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Microsoft.NET.Build.Tasks
{
internal class ProjectContext
{
private const string NetCorePlatformLibrary = "Microsoft.NETCore.App";

private readonly LockFile _lockFile;
private readonly LockFileTarget _lockFileTarget;
internal HashSet<PackageIdentity> PackagesToBeFiltered { get; set; }
Expand Down Expand Up @@ -63,6 +65,17 @@ public IEnumerable<LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable<string
if (IsFrameworkDependent)
{
allExclusionList.UnionWith(_lockFileTarget.GetPlatformExclusionList(PlatformLibrary, libraryLookup));

// If the platform library is not Microsoft.NETCore.App, treat it as an implicit dependency.
// This makes it so Microsoft.AspNet.* 2.x platforms also exclude Microsoft.NETCore.App files.
if (PlatformLibrary.Name.Length > 0 && !String.Equals(PlatformLibrary.Name, NetCorePlatformLibrary, StringComparison.OrdinalIgnoreCase))
{
var library = _lockFileTarget.GetLibrary(NetCorePlatformLibrary);
if (library != null)
{
allExclusionList.UnionWith(_lockFileTarget.GetPlatformExclusionList(library, libraryLookup));
}
}
}

if (excludeFromPublishPackageIds?.Any() == true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.NET.Publish.Tests
{
public class GivenThatWeWantToPublishAWebProject : SdkTest
{
public GivenThatWeWantToPublishAWebProject(ITestOutputHelper log) : base(log)
{
}

[Fact]
public void It_should_publish_self_contained()
{
var tfm = "netcoreapp2.2";

var testProject = new TestProject()
{
Name = "WebTest",
TargetFrameworks = tfm,
IsSdkProject = true,
IsExe = true,
};

testProject.AdditionalProperties.Add("AspNetCoreHostingModel", "InProcess");
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.AspNetCore.App"));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.AspNetCore.Razor.Design", version: "2.2.0", privateAssets: "all"));

var testProjectInstance = _testAssetsManager.CreateTestProject(testProject)
.WithProjectChanges(
(filename, project) =>
{
project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";
});

var command = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name));

var rid = EnvironmentInfo.GetCompatibleRid(tfm);
command
.Execute("/restore", $"/p:RuntimeIdentifier={rid}")
.Should()
.Pass();

var output = command.GetOutputDirectory(
targetFramework: tfm,
runtimeIdentifier: rid);

output.Should().HaveFiles(new[] {
$"{testProject.Name}{Constants.ExeSuffix}",
$"{testProject.Name}.dll",
$"{testProject.Name}.pdb",
$"{testProject.Name}.deps.json",
$"{testProject.Name}.runtimeconfig.json",
"web.config",
$"{FileConstants.DynamicLibPrefix}hostfxr{FileConstants.DynamicLibSuffix}",
$"{FileConstants.DynamicLibPrefix}hostpolicy{FileConstants.DynamicLibSuffix}",
});

output.Should().NotHaveFiles(new[] {
$"apphost{Constants.ExeSuffix}",
});

Command.Create(Path.Combine(output.FullName, $"{testProject.Name}{Constants.ExeSuffix}"), new string[] {})
.CaptureStdOut()
.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}


[Theory]
[InlineData("Microsoft.AspNetCore.App")]
[InlineData("Microsoft.AspNetCore.All")]
public void It_should_publish_framework_dependent(string platformLibrary)
{
var tfm = "netcoreapp2.2";

var testProject = new TestProject()
{
Name = "WebTest",
TargetFrameworks = tfm,
IsSdkProject = true,
IsExe = true,
};

testProject.AdditionalProperties.Add("AspNetCoreHostingModel", "InProcess");
testProject.PackageReferences.Add(new TestPackageReference(platformLibrary));
testProject.PackageReferences.Add(new TestPackageReference("Microsoft.AspNetCore.Razor.Design", version: "2.2.0", privateAssets: "all"));

var testProjectInstance = _testAssetsManager.CreateTestProject(testProject)
.WithProjectChanges(
(filename, project) =>
{
project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";
});

var command = new PublishCommand(Log, Path.Combine(testProjectInstance.Path, testProject.Name));

var rid = EnvironmentInfo.GetCompatibleRid(tfm);
command
.Execute("/restore", $"/p:RuntimeIdentifier={rid}", "/p:SelfContained=false")
.Should()
.Pass();

var output = command.GetOutputDirectory(
targetFramework: tfm,
runtimeIdentifier: rid);

output.Should().OnlyHaveFiles(new[] {
$"{testProject.Name}{Constants.ExeSuffix}",
$"{testProject.Name}.dll",
$"{testProject.Name}.pdb",
$"{testProject.Name}.deps.json",
$"{testProject.Name}.runtimeconfig.json",
"web.config",
});

Command.Create(Path.Combine(output.FullName, $"{testProject.Name}{Constants.ExeSuffix}"), new string[] {})
.EnvironmentVariable(
Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)",
Path.GetDirectoryName(TestContext.Current.ToolsetUnderTest.DotNetHostPath))
.CaptureStdOut()
.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder)
{
packageReferenceElement.Add(new XAttribute("Version", packageReference.Version));
}
if (packageReference.PrivateAssets != null)
{
packageReferenceElement.Add(new XAttribute("PrivateAssets", packageReference.PrivateAssets));
}
packageReferenceItemGroup.Add(packageReferenceElement);
}

Expand Down
10 changes: 3 additions & 7 deletions src/Tests/Microsoft.NET.TestFramework/TestPackageReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ namespace Microsoft.NET.TestFramework
{
public class TestPackageReference
{
public TestPackageReference(string id, string version)
: this(id, version, null)
{
}

public TestPackageReference(string id, string version, string nupkgPath)
public TestPackageReference(string id, string version = null, string nupkgPath = null, string privateAssets = null)
{
ID = id;
Version = version;
NupkgPath = nupkgPath;
PrivateAssets = privateAssets;
}

public string ID { get; private set; }
public string Version { get; private set; }
public string NupkgPath { get; private set; }

public string PrivateAssets { get; private set; }

public bool NuGetPackageExists()
{
Expand Down