#postsharp 添加 PostSharp.Community nuget 包后无法编译(在 Mac 上)

#postsharp Unable to compile after adding PostSharp.Community nuget package (on a Mac)

我正在使用 Mac 和 Visual Studio 2019。我添加了 nuget 包:PostSharp 和 PostSharp.Community。我没有更改任何代码。我没有收到 select 许可证的提示。我只是想编译,但出现以下错误。

/var/tmp/postsharp/cache/DependencyRestore/6.0.101/net6.0-sdk6.0.101-osx-x64--ps6.10.6.0-cf0d89f.deps.proj : error NU3034: Package 'System.ValueTuple 4.4.0' from source 'https://api.nuget.org/v3/index.json': This package is signed but not by a trusted signer. /var/tmp/postsharp/cache/DependencyRestore/6.0.101/net6.0-sdk6.0.101-osx-x64--ps6.10.6.0-cf0d89f.deps.proj : error NU3037: Package 'System.Security.Cryptography.ProtectedData 4.4.0' from source 'https://api.nuget.org/v3/index.json': The repository primary signature validity period has expired.

我的项目是针对框架NetCore3.1。不知道为什么PostSharp会提到net6.0

我一删除 PostSharp 包,它就可以正常编译了。

任何帮助,将不胜感激。

谢谢, 杰森

您的机器上可能安装了.NET 6.0 SDK,它是活动的SDK(通常默认使用最高版本)。 PostSharp 始终在与当前 SDK 关联的 运行 时间内执行。

您应该使用 the global.json file 指定 .NET Core 3.1 的 SDK。这会导致 PostSharp 在 .NET Core 3.1 上 运行。

如果这没有帮助,则意味着无法从 nuget.org 安装 PostSharp 的依赖包。

您可以通过设置 DependencyRestoreDisabled=True(作为 env var 或 MSBuild 属性)来禁用 PostSharp 的依赖项恢复,并确保生成到 /var/tmp/postsharp/cache/DependencyRestore/<SdkVersion>/<id>.proj 中的项目具有所有依赖项\var\tmp\postsharp\NuGetFallback 目录。

禁用依赖项恢复会禁用自动检查并假定 PostSharp 可以在机器上找到它的所有依赖项。

我添加了 global.json,删除了 SDK 6.x。设置 PostSharpDependencyRestoreDisabled=True 然后我必须手动添加所有引用的 Nuget 包。这很烦人,但至少现在可以用了。

Daniel,考虑到你的两个回复,我能够修复它!

谢谢!