简体   繁体   中英

How to remove default/locked assembly reference from .NET SDK csproj that is targeting full .NET Framework?

I have a new csproj format project that is using <TargetFramework.net472</TargetFramework> (targeting full .NET Framework), which adds default set of immutable assembly references to the project (as shown on the screenshot).

伊姆古尔

For example, System.Drawing is locked and can not be removed.

Yes, I know, if I don't use any classes from System.Drawing , it will not be actually referenced.

But still, is there any way to remove/ignore/hide it?

I've already tried alias trick to hide it:

<Reference Update="System.Drawing">
  <Aliases>excluded</Aliases>
  <Private>false</Private>
</Reference>

Did not work.

I have nothing against System.Drawing per se — but, what if I have another assembly which exports types with exact same namespaces and names — how to "shadow" existing reference?

Update: csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
    </PropertyGroup>
</Project>

By default System.Drawing is not referenced in new .net 4.7.2 project.

And if u reference it, u can remove reference when u want it

在此处输入图片说明

Just in case anybody is still searching for an answer: set the DisableImplicitFrameworkReferences property to true, then add references to the assemblies that are actually needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM