简体   繁体   English

如何从针对完整 .NET 框架的 .NET SDK csproj 中删除默认/锁定程序集引用?

[英]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).我有一个新的 csproj 格式项目,它正在使用<TargetFramework.net472</TargetFramework> (针对完整的 .NET 框架),它向项目添加了一组默认的不可变程序集引用(如屏幕截图所示)。

伊姆古尔

For example, System.Drawing is locked and can not be removed.例如, System.Drawing已锁定且无法删除。

Yes, I know, if I don't use any classes from System.Drawing , it will not be actually referenced.是的,我知道,如果我不使用System.Drawing中的任何类,它就不会被实际引用。

But still, is there any way to remove/ignore/hide it?但是,有什么办法可以删除/忽略/隐藏它吗?

I've already tried alias trick to hide it:我已经尝试过alias技巧来隐藏它:

<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?我并不反对System.Drawing本身——但是,如果我有另一个程序集导出具有完全相同的命名空间和名称的类型——如何“隐藏”现有引用呢?

Update: csproj looks like this:更新:csproj 看起来像这样:

<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. 默认情况下,新.net 4.7.2项目中未引用System.Drawing。

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.以防万一有人仍在寻找答案:将DisableImplicitFrameworkReferences属性设置为 true,然后添加对实际需要的程序集的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的项目可以引用针对较低版本.net框架的程序集吗? - Can my project reference an assembly targeting a lower version of .net framework? UWP-使用面向.NET Framework 4.6的程序集 - UWP - Use assembly targeting .NET Framework 4.6 如何从以net462为目标的SDK项目中引用System.Windows.Forms - How to reference System.Windows.Forms from a net462 targeting SDK project .Net Framework 4 Full 和 Net Framework 4 Client Profile Targeting - .Net Framework 4 Full and Net Framework 4 Client Profile Targeting 如何在matlab中删除对.net程序集的引用 - how to remove reference to .net assembly in matlab 从现有 csproj 获取默认命名空间(Microsoft.NET.Sdk 格式) - Get default namespace from existing csproj (Microsoft.NET.Sdk format) 从.csproj目标4.5.1引用目标为4.5.2的程序集给出错误 - Referencing assembly targeting 4.5.2 from .csproj targeting 4.5.1 gives error 面向.NET Framework 4.0 - Targeting .NET Framework 4.0 从.NET Framework传统项目引用.NET Standard csproj项目 - Referencing .NET Standard csproj project from .NET Framework traditional project ASP.NET Core使用EF6和Identity定位完整框架 - ASP.NET Core targeting full framework with EF6 and Identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM