Setting PreserveCompilationContext=false trims Microsoft.AspNetCore.App shared runtime in deps files
See original GitHub issueFrom @pranavkm on March 26, 2018 17:18
Steps to reproduce
- Create an webapi \ mvc \ emptyweb application using preview1 (or preview2) Sdk
- Build the project
The generated deps file will say that the application references both Microsoft.NETCore.App
and Microsoft.AspNetCore.App
:
"blah/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.App": "2.1.0-preview1-final",
"Microsoft.NETCore.App": "2.1.0-preview1-26216-03"
},
"runtime": {
"blah.dll": {}
},
"compile": {
"blah.dll": {}
}
},
- Delete the bin directory. Edit the csproj
<PreserveCompilationContext>false</PreserveCompilationContext>
. Rebuild the project - The generated deps file will say that the app no longer references
Microsoft.AspNetCore.App
:
"blah/1.0.0": {
"dependencies": {
"Microsoft.NETCore.App": "2.1.0-preview1-26216-03"
},
"runtime": {
"blah.dll": {}
}
},
Environment data
.NET Command Line Tools (2.1.300-preview1-008174)
Product Information:
Version: 2.1.300-preview1-008174
Commit SHA-1 hash: b8df89a54f
Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Users\Pranav\Downloads\dotnet-sdk-2.1.300-preview1-008174-win-x64\sdk\2.1.300-preview1-008174\
Microsoft .NET Core Shared Framework Host
Version : 2.1.0-preview1-26216-03
Build : f2c3216183d20416568a4bbf5bb7d153e826f153
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 reference Microsoft.AspNetCore.App
-> Microsoft.AspNetCore.Mvc
. Consequently no controllers are discovered.
Copied from original issue: dotnet/core-setup#3902
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
PreserveCompilationContext not configured by default - .NET
Learn about the breaking change in ASP.NET Core 6.0 where the PreserveCompilationContext property is no longer configured by default.
Read more >Exploring the Microsoft.AspNetCore.App shared framework ...
When you publish your app, the Microsoft.AspNetCore.All metapackage trims out all the dependencies that it knows will be in the runtime store, ...
Read more >What is deps.json, and how do I make it use relative paths?
The answer to your first question, per the Runtime Configuration File Documentation: And the answer to your second question, is to remove ...
Read more >Deep-dive into .NET Core primitives, part 2: the shared ...
To put it simply, a .NET Core shared framework is a folder of assemblies (*.dll files) that are not in the application folder....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?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.
Going with https://github.com/dotnet/sdk/issues/2092#issuecomment-377050440, which is tracked by #2122.