我有一个当前针对 NetStandard1.4
的项目。
我正在尝试使其成为多目标框架:
net461
netstandard14
netstandard20
合理性是针对特定框架(应用程序目标),仅下拉最少数量的程序集。因此,在上面的示例中,ns14
的最小框架为 461
,但是针对 net461
的应用程序会提取一些人们所关注的核心内容。当这些组件没有被使用时,这句话会增加额外的噪音。
当我尝试针对这 3 个框架时,我在 NetStandard2.0
版本中收到一些警告。
我尝试将鼠标悬停在 Visual Studio 中的该程序集上,但没有显示工具提示。此外,错误列表或输出(构建)窗口没有任何解释。
有什么方法可以让我看到警告是什么?甚至可以通过 CLI?
最佳答案
您正在 .netStandard 项目中引用 System.Net.Http
。此引用已存在于 NetStandard.Library
中,因此您无需添加它。大多数时候,您应该只引用项目或 NuGet 包。
在我的计算机上,dotnet build
确实失败并出现以下警告:
C:\Program Files\dotnet\sdk\2.1.100-preview-007326\Microsoft.Common.CurrentVersion.targets(2051,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Net.Http". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
如果您不想添加对 NetStandard.Library 的引用,解决方案是使用 Condition
属性仅添加对 net461 版本的引用:
<PropertyGroup>
<TargetFrameworks>net461;netstandard1.4;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<Reference Include="System.Net.Http" />
</ItemGroup>
关于c# - 为什么我的 .NET Standard 2.0(多目标)项目对依赖程序集之一发出警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48554116/