Closed eerhardt closed 5 years ago
From @pranavkm on March 26, 2018 17:57
Spoke to @eerhardt, the missing shared runtime isn't necessarily the cause for concern here - a console app's deps file also does not include a reference to the shared runtime Microsoft.NETCore.App
. The issue is that DependencyContext.Load
does not merge shared fx deps files. The suggested fix is to add a new overload to DependencyContext.Load
that walks up the fx chain and merges the runtime deps files. MVC can consume this API once this is available.
cc @rynowak \ @steveharter \ @mkArtakMSFT
Looking more, the DependencyContext.Load
DOES merge in the shared fx deps files.
The issue is that the Dependency
information is getting trimmed, so there is no link from the application's library to the MVC library. Or similarly, if the application references another project that contains controllers, that project won't have a Dependency on the MVC library either. This trimming logic is in the dotnet/sdk
repo. Moving this issue there.
See https://github.com/dotnet/sdk/blob/935ac5fde8d917b1de3b18d038232f15527572aa/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs#L63-L66 for where the PlatformLibrary
s get trimmed.
@dsplaisted please take a look.
Some more thoughts about this:
Assuming the plan is to preserve the "Dependency" entries, even when the Platform library is trimmed:
shared fx
.deps.json. When this happens, if there is code trying to resolve those dependencies it will fail to find the referenced library.v2.1.0
and the asp.net shared fx rolled forward to v2.1.6
or even v2.2.0
, using the Dependency.Version to match on strings will not work. Stepping back, the primary driver for turning off PreserveCompilationContext
is to avoid publishing the refs directory when an application does not require it (e.g. when you're writing an application not using runtime compiled views). Right now, there's a single switch that determines the structure of the deps file and the published refs directory. Could we possibly introduce a new switch that controls publishing the refs directory?
// Microsoft.NET.Sdk.Razor.targets
<!-- Use PreserveCompilationContext's value if it was explicitly set in the user's project -->
<PreserveCompilationReferences Condition="'$(PreserveCompilationContext)' != ''">$(PreserveCompilationContext)</PreserveCompilationReferences>
<!-- Initialize PreserveCompilationContext -->
<PreserveCompilationReferences Condition="'$(PreserveCompilationReferences )' == ''">true</PreserveCompilationReferences>
Targets in Microsoft.NET.Sdk that control publishing would be modified to rely on this new switch: https://github.com/dotnet/sdk/blob/6945e3694c918eea4c8c4fb6217e1485b179994b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PreserveCompilationContext.targets#L45-L46 https://github.com/dotnet/sdk/blob/6945e3694c918eea4c8c4fb6217e1485b179994b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PreserveCompilationContext.targets#L84-L85
It's a breaking change for users relying on the refs directory in non-web scenarios, but I'm not sure if that's a common scenario.
Duplicate of dotnet/sdk#2122
Going with https://github.com/dotnet/sdk/issues/2092#issuecomment-377050440, which is tracked by #2122.
From @pranavkm on March 26, 2018 17:18
Steps to reproduce
The generated deps file will say that the application references both
Microsoft.NETCore.App
andMicrosoft.AspNetCore.App
:<PreserveCompilationContext>false</PreserveCompilationContext>
. Rebuild the projectMicrosoft.AspNetCore.App
:Environment data
More information:
The bulk of MVC's controller discovery model is based on finding libraries that directly or transitively depend on any one of Mvc's libraries. In 2.1.0-preview2, the Razor.Sdk only sets
PreserveCompilationContext=true
if the app has any files that require runtime compilation. For projects without views, such as webapi or empty web template, the produced deps file claims that the app does not referenceMicrosoft.AspNetCore.App
->Microsoft.AspNetCore.Mvc
. Consequently no controllers are discovered.Copied from original issue: dotnet/core-setup#3902