Skip to content

Add better assembly resolve for PublishTrimmed build option for AspNet Core #18781

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

Closed
jeremielec opened this issue Feb 4, 2020 · 4 comments
Closed
Labels
affected-few This issue impacts only small number of customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform investigate linker-friendliness Tracking linker friendliness severity-minor This label is used by an internal tool

Comments

@jeremielec
Copy link

Is your feature request related to a problem? Please describe.

A major feature of .Net core is now to allow project to be publish trimmed (Aka removing unused assembly) and self-contained.
This does not work fine with AspNet Core, as stated here, use reflexion.
Therefore used type in controllers are mostly stripped out (Like smtpclient). Occur if the type is created directly in controllers or injected via dependencies injection.

Describe the solution you'd like

Improve PublishTrimmed option for not remove directly used assembly by controllers.

Additional context

Attached sample project with a simple route /test

TrimProblemExample.zip

This work fine when lauched with visual studio.
This not work with bellow error when lauched with standalone publish with

dotnet publish WebApplication5.csproj --output out

(note that publish option are in the csproj)

Unhandled exception. System.TypeLoadException: Could not load type 'System.Net.Mail.SmtpClient' from assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

@javiercn javiercn added the feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform label Feb 4, 2020
@mmarinchenko
Copy link

mmarinchenko commented Mar 13, 2020

+1

dotnet publish generates .deps.json file wich contains dependencies section. In my case System.Resources.ResourceManager assembly was trimmed out from output directory while existing in dependencies section of .deps.json file.

I had to add the following to project configuration to solve this:

  <ItemGroup>
    <TrimmerRootAssembly Include="System.Resources.ResourceManager" />
  </ItemGroup>

Two different dependency resolvers in one command?

@romanryasne2
Copy link

Any updates?

@JunTaoLuo JunTaoLuo added linker-friendliness Tracking linker friendliness area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates investigate and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates linker-friendliness Tracking linker friendliness labels Sep 30, 2020
@wtgodbe wtgodbe added affected-few This issue impacts only small number of customers linker-friendliness Tracking linker friendliness severity-minor This label is used by an internal tool labels Dec 21, 2020
@wtgodbe
Copy link
Member

wtgodbe commented Dec 21, 2020

@javiercn @Pilchie thoughts on who should take a look at this?

@davidfowl
Copy link
Member

Closing as part of #27384

@ghost ghost locked as resolved and limited conversation to collaborators Feb 28, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-platform Deprecated: Cross-cutting issues related to ASP.NET Core as a platform investigate linker-friendliness Tracking linker friendliness severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

8 participants