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

Enable RID-specific Apps on Shared Framework #1053

Merged
merged 5 commits into from
Apr 3, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void ItBuildsDependencyContextsFromProjectLockFiles(
ProjectContext projectContext = lockFile.CreateProjectContext(
FrameworkConstants.CommonFrameworks.NetCoreApp10,
runtime,
Constants.DefaultPlatformLibrary);
Constants.DefaultPlatformLibrary,
isSelfContained: !string.IsNullOrEmpty(runtime));

DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext)
.WithDirectReferences(directReferences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public void ItComputesPrivateAssetsExclusionList()
ProjectContext projectContext = lockFile.CreateProjectContext(
FrameworkConstants.CommonFrameworks.NetStandard16,
null,
Constants.DefaultPlatformLibrary);
Constants.DefaultPlatformLibrary,
isSelfContained: false);

IEnumerable<string> privateAssetPackageIds = new[] { "Microsoft.Extensions.Logging.Abstractions" };
IDictionary<string, LockFileTargetLibrary> libraryLookup =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void ItResolvesAssembliesFromProjectLockFiles(string projectName, string
ProjectContext projectContext = lockFile.CreateProjectContext(
FrameworkConstants.CommonFrameworks.NetCoreApp10,
runtime,
Constants.DefaultPlatformLibrary);
Constants.DefaultPlatformLibrary,
isSelfContained: false);

IEnumerable<ResolvedFile> resolvedFiles = new PublishAssembliesResolver(new MockPackageResolver())
.Resolve(projectContext);
Expand All @@ -42,7 +43,8 @@ public void ItResolvesAssembliesFromProjectLockFilesWithCacheLayout(string proje
ProjectContext projectContext = lockFile.CreateProjectContext(
FrameworkConstants.CommonFrameworks.NetCoreApp10,
runtime,
Constants.DefaultPlatformLibrary);
Constants.DefaultPlatformLibrary,
isSelfContained: false);

IEnumerable<ResolvedFile> resolvedFiles = new PublishAssembliesResolver(new MockPackageResolver())
.WithPreserveCacheLayout(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Security.Cryptography;
using System.Text;
using Microsoft.Extensions.DependencyModel;
using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.ProjectModel;
Expand Down Expand Up @@ -125,7 +124,9 @@ public DependencyContext Build()
_projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName,
_projectContext.LockFileTarget.RuntimeIdentifier,
runtimeSignature,
_projectContext.IsPortable);
// DependencyContext's IsPortable strictly means it doesn't have a runtime dependency,
// not whether it is FrameworkDependent or !SelfContained.
isPortable: string.IsNullOrEmpty(_projectContext.LockFileTarget.RuntimeIdentifier));

return new DependencyContext(
targetInfo,
Expand Down
6 changes: 4 additions & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.Build.Utilities;
using Microsoft.Extensions.DependencyModel;
using Newtonsoft.Json;
using NuGet.Frameworks;
using NuGet.ProjectModel;

namespace Microsoft.NET.Build.Tasks
Expand Down Expand Up @@ -55,6 +54,8 @@ public class GenerateDepsFile : TaskBase

public ITaskItem[] PrivateAssetsPackageReferences { get; set; }

public bool IsSelfContained { get; set; }

List<ITaskItem> _filesWritten = new List<ITaskItem>();

[Output]
Expand Down Expand Up @@ -90,7 +91,8 @@ protected override void ExecuteCore()
ProjectContext projectContext = lockFile.CreateProjectContext(
NuGetUtils.ParseFrameworkName(TargetFramework),
RuntimeIdentifier,
PlatformLibraryName);
PlatformLibraryName,
IsSelfContained);

DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext)
.WithFrameworkReferences(frameworkReferences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class GenerateRuntimeConfigurationFiles : TaskBase

public ITaskItem[] HostConfigurationOptions { get; set; }

public bool IsSelfContained { get; set; }

List<ITaskItem> _filesWritten = new List<ITaskItem>();

[Output]
Expand All @@ -57,7 +59,8 @@ protected override void ExecuteCore()
ProjectContext projectContext = lockFile.CreateProjectContext(
NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker),
RuntimeIdentifier,
PlatformLibraryName);
PlatformLibraryName,
IsSelfContained);

WriteRuntimeConfig(projectContext);

Expand Down Expand Up @@ -86,7 +89,7 @@ private void WriteRuntimeConfig(ProjectContext projectContext)

private void AddFramework(RuntimeOptions runtimeOptions, ProjectContext projectContext)
{
if (projectContext.IsPortable)
if (projectContext.IsFrameworkDependent)
{
var platformLibrary = projectContext.PlatformLibrary;
if (platformLibrary != null)
Expand Down
8 changes: 6 additions & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static ProjectContext CreateProjectContext(
this LockFile lockFile,
NuGetFramework framework,
string runtime,
string platformLibraryName)
string platformLibraryName,
bool isSelfContained)
{
if (lockFile == null)
{
Expand All @@ -39,7 +40,10 @@ public static ProjectContext CreateProjectContext(
throw new BuildErrorException(Strings.AssetsFileMissingTarget, lockFile.Path, targetMoniker, framework.GetShortFolderName(), runtime);
}

return new ProjectContext(lockFile, lockFileTarget, platformLibraryName);
LockFileTargetLibrary platformLibrary = lockFileTarget.GetLibrary(platformLibraryName);
bool isFrameworkDependent = platformLibrary != null && (!isSelfContained || string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier));

return new ProjectContext(lockFile, lockFileTarget, platformLibrary, isFrameworkDependent);
}

public static LockFileTargetLibrary GetLibrary(this LockFileTarget lockFileTarget, string libraryName)
Expand Down
31 changes: 17 additions & 14 deletions src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
// 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 NuGet.Packaging.Core;
using NuGet.ProjectModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Linq;
using NuGet.ProjectModel;
using NuGet.Packaging.Core;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.NET.Build.Tasks
{
internal class ProjectContext
{
private readonly LockFile _lockFile;
private readonly LockFileTarget _lockFileTarget;
private readonly string _platformLibraryName;
internal HashSet<PackageIdentity> PackagesToBeFiltered { get; set; }

public bool IsPortable { get; }
public bool IsFrameworkDependent { get; }
public LockFileTargetLibrary PlatformLibrary { get; }

public LockFile LockFile => _lockFile;
public LockFileTarget LockFileTarget => _lockFileTarget;

public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget, string platformLibraryName)
public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget, LockFileTargetLibrary platformLibrary, bool isFrameworkDependent)
{
Debug.Assert(lockFile != null);
Debug.Assert(lockFileTarget != null);
if (isFrameworkDependent)
{
Debug.Assert(platformLibrary != null);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug.Assert(!isFrameworkDependent || platformLibrary != null) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of like the readability of the way it is. It is very straight-forward to understand (at least to me). The compiler will remove the if statement in release mode, since it is empty, so it isn't like it will affect the outputted assembly code.

Do you have a strong opinion on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion.


_lockFile = lockFile;
_lockFileTarget = lockFileTarget;
_platformLibraryName = platformLibraryName;

PlatformLibrary = _lockFileTarget.GetLibrary(_platformLibraryName);
IsPortable = PlatformLibrary != null && string.IsNullOrEmpty(_lockFileTarget.RuntimeIdentifier);
PlatformLibrary = platformLibrary;
IsFrameworkDependent = isFrameworkDependent;
}

public IEnumerable<LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable<string> privateAssetPackageIds)
Expand All @@ -43,7 +46,7 @@ public IEnumerable<LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable<string

HashSet<string> allExclusionList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

if (IsPortable)
if (IsFrameworkDependent)
{
allExclusionList.UnionWith(_lockFileTarget.GetPlatformExclusionList(PlatformLibrary, libraryLookup));
}
Expand All @@ -58,7 +61,7 @@ public IEnumerable<LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable<string
allExclusionList.UnionWith(privateAssetsExclusionList);
}

if(PackagesToBeFiltered != null)
if (PackagesToBeFiltered != null)
{
var filterLookup = new Dictionary<string, HashSet<PackageIdentity>>(StringComparer.OrdinalIgnoreCase);
foreach (var pkg in PackagesToBeFiltered)
Expand Down Expand Up @@ -201,7 +204,7 @@ private static HashSet<string> GetPackagesToBeFiltered(
IDictionary<string, LockFileTargetLibrary> packagesToBePublished)
{
var exclusionList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var entry in packagesToBePublished)
{
HashSet<PackageIdentity> librarySet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ResolvePublishAssemblies : TaskBase

public string[] FilterProjectFiles { get; set; }

public bool IsSelfContained { get; set; }

/// <summary>
/// All the assemblies to publish.
/// </summary>
Expand Down Expand Up @@ -80,7 +82,8 @@ protected override void ExecuteCore()
ProjectContext projectContext = lockFile.CreateProjectContext(
NuGetUtils.ParseFrameworkName(TargetFramework),
RuntimeIdentifier,
PlatformLibraryName);
PlatformLibraryName,
IsSelfContained);

projectContext.PackagesToBeFiltered = packagestoBeFiltered;

Expand Down
51 changes: 29 additions & 22 deletions src/Tasks/Microsoft.NET.Build.Tasks/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Tasks/Microsoft.NET.Build.Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,7 @@
<data name="FileNameIsTooLong" xml:space="preserve">
<value>Given file name '{0}' is longer than 1024 bytes</value>
</data>
<data name="CannotHaveSelfContainedWithoutRuntimeIdentifier" xml:space="preserve">
<value>It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. Please either specify a RuntimeIdentifier or set SelfContained to false.</value>
</data>
</root>
Loading