gpt4 book ai didi

c# - 'HttpClientHandler' 不包含 'ClientCertificates' 在 net461 和 net47 中的定义?

转载 作者:行者123 更新时间:2023-11-30 22:56:41 33 4
gpt4 key购买 nike

我正在制作一个 NuGet 包,我的 csproj 看起来像这样:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
...
<PackageId>Package2</PackageId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Package1\Package1.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<Reference Include="System.Net.Http" />
</ItemGroup>

</Project>

它引用的项目如下所示:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.6;net461;net47</TargetFrameworks>
<PackageId>Package1</PackageId>
...
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<NoWarn>1701;1702; CS1591</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<Reference Include="System.Net.Http" />
</ItemGroup>

</Project>

Package2 项目中有以下行:

webRequestHandler.ClientCertificates.Add(certificate);

但它不是在 net461net47 中构建,说:

'HttpClientHandler' does not contain a definition for 
'ClientCertificates' and no accessible extension method
'ClientCertificates' accepting a first argument of type
'HttpClientHandler' could be found (are you missing a using
directive or an assembly reference?)

Package2(net461),
Package2(net47)

但我唯一改变的是从 package2 的 csproj 中删除了它:

  <ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6' OR '$(TargetFramework)'=='net461' OR '$(TargetFramework)'=='net47'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="1.1.2" />
</ItemGroup>

任何人都可以帮助我了解如何修复它吗?我真的不想引入整个 NuGet 包来修复这个依赖项我想我只是缺少一个程序集但据我所知它应该在 System.Net.Http我应该已经引用了它(它已经依赖的其他项目也应该引用)。

最佳答案

看起来这个属性从版本 4.7.1 开始可用:

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.clientcertificates?view=netframework-4.7.1

请注意,如果您选择较旧的 .NET 版本,您将看到如下消息:

The requested page is not available for .NET Framework 4.7.

关于c# - 'HttpClientHandler' 不包含 'ClientCertificates' 在 net461 和 net47 中的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54234646/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com