gpt4 book ai didi

c# - 单元测试公共(public)签名的 .NET Core/框架库

转载 作者:行者123 更新时间:2023-12-02 03:05:35 26 4
gpt4 key购买 nike

我有一个针对 .NET Core 和 .NET Framework 进行编译的 NuGet 包库项目。它还使用新的 public signing .

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

<PropertyGroup Label="Build">
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Label="Signing">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../Key.snk</AssemblyOriginatorKeyFile>
<PublicSign>true</PublicSign>
</PropertyGroup>

</Project>

我有一个 xUnit 测试项目,使用它也可以交叉编译到 .NET Core 和 .NET Framework。

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

<PropertyGroup Label="Build">
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
</PropertyGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

<ItemGroup Label="Project References">
<ProjectReference Include="..\..\Source\Foo\Foo.csproj" />
</ItemGroup>

</Project>

当我在此项目中运行测试时,.NET Core 测试运行成功,但 .NET Framework 测试运行失败,并显示:

System.IO.FileLoadException : Could not load file or assembly 'Foo, Version=0.0.1.0, Culture=neutral, PublicKeyToken=fc5550082a9c642c' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

我怎样才能让它们都工作?

最佳答案

使用

<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">True</PublicSign>

引用

#SNMP Library

关于c# - 单元测试公共(public)签名的 .NET Core/框架库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60058571/

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