-
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
Enable RID-specific Apps on Shared Framework #1053
Conversation
This option enables a RID-specific application to still use the shared framework.
Allow .NET Core applications to be RID-specific, but still run on the Shared Framework. This enables an application to carry only the native assets it needs for the specific runtime it intends to run on. For example, if an application uses a graphics library and wants to run on the shared framework, it would carry that graphics library for all the runtimes the graphics library supported (win, osx, linux, x86, x64, arm, etc). But if the application is only intended to run on one runtime, these extra assemblies bloat the app.
@@ -125,7 +124,7 @@ public DependencyContext Build() | |||
_projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName, | |||
_projectContext.LockFileTarget.RuntimeIdentifier, | |||
runtimeSignature, | |||
_projectContext.IsPortable); | |||
isPortable: string.IsNullOrEmpty(_projectContext.LockFileTarget.RuntimeIdentifier)); |
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.
Why do we use the RID check here but plumb IsSelfContained elsewhere?
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.
I need to add a comment here.
Basically, IsPortable
!= IsFrameworkDependent
and IsPortable
!= !IsSelfContained
.
But IsFrameworkDependent
== !IsSelfContained
. (for now until we add some other app model where it doesn't run on a shared framework and still isn't self-contained.)
IsPortable
means your app can run on any machine. It is portable across architectures, OSes, etc.
IsFrameworkDependent
means your app runs on the shared framework, but it can still be runtime-specific. note: IsPortable
implies IsFrameworkDependent
IsSelfContained
means everything required to run your app is located in your publish output.
In this case, DependencyModel is strictly asking for IsPortable
, not IsFrameworkDependent
or !IsSelfContained
. And looking under the hood, DependencyModel treats IsPortable
and an empty RuntimeIdentifier
the same. In a perfect world, this boolean wouldn't be needed to be passed here.
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.
Thanks for the thorough explanation.
Add a comment for DependencyContext IsPortable usage.
After dotnet/sdk#1053 is merged, it is possible for an app to run on the shared framework, but not be "portable". DependencyContextLoader should always load the "runtime" context, if it is present. Also, with #1597, there may be other deps files for the app. It should load those as well. Fix #1886
@nguerrera @dsplaisted - can you take a look? I'd like to get this merged today. |
@@ -24,7 +24,8 @@ public void ItResolvesAssembliesFromProjectLockFiles(string projectName, string | |||
ProjectContext projectContext = lockFile.CreateProjectContext( | |||
FrameworkConstants.CommonFrameworks.NetCoreApp10, | |||
runtime, | |||
Constants.DefaultPlatformLibrary); | |||
Constants.DefaultPlatformLibrary, | |||
false); |
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.
Please use named arguments for bools.
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.
Done on both of these.
@@ -42,7 +43,8 @@ public void ItResolvesAssembliesFromProjectLockFilesWithCacheLayout(string proje | |||
ProjectContext projectContext = lockFile.CreateProjectContext( | |||
FrameworkConstants.CommonFrameworks.NetCoreApp10, | |||
runtime, | |||
Constants.DefaultPlatformLibrary); | |||
Constants.DefaultPlatformLibrary, | |||
false); |
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.
Ditto, named argument.
if (isFrameworkDependent) | ||
{ | ||
Debug.Assert(platformLibrary != null); | ||
} |
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.
Debug.Assert(!isFrameworkDependent || platformLibrary != null)
?
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.
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?
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.
I don't have a strong opinion.
This is necessary because of dotnet/sdk#1053
This is necessary for dotnet/sdk#1053
This flows to the $(SelfContained) property added in dotnet/sdk#1053
This flows to the $(SelfContained) property added in dotnet/sdk#1053
…0191030.11 (dotnet#1053) - Microsoft.AspNetCore.Analyzers - 3.1.0-preview3.19530.11 - Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.1.0-preview3.19530.11 - Microsoft.AspNetCore.Mvc.Analyzers - 3.1.0-preview3.19530.11 - Microsoft.AspNetCore.Components.Analyzers - 3.1.0-preview3.19530.11
Allow .NET Core applications to be RID-specific, but still run on the Shared Framework. This enables an application to carry only the native assets it needs for the specific runtime it intends to run on.
For example, if an application uses a graphics library and wants to run on the shared framework, it would carry that graphics library for all the runtimes the graphics library supported (win, osx, linux, x86, x64, arm, etc). But if the application is only intended to run on one runtime, these extra assemblies bloat the app.
@ericstj @nguerrera @dsplaisted @livarcocc
/cc @Petermarcu
Notes:
There are 2 other changes that need to go into other repos:
--self-contained[:false|true]
, which flows into the MSBuild$(SelfContained)
property added here.A future, potential scenario is to publish self-contained, but don't specify any RID. This won't work today because
dotnet restore
hasn't restored for that RID, thus the necessary assets are not available. This can be revisited when restore occurs during publish. For now, that scenario raises an error with a message saying it is unsupported.