构建时缺少类型或命名空间名称 'InternalsVisibleToAttribute'

The type or namespace name 'InternalsVisibleToAttribute' missing on build

我最近设置了一个项目以在 AppVeyor 上构建以获取构建徽章和 GitHub 集成,但出现错误 The type or namespace name 'InternalsVisibleToAttribute' could not be found (are you missing a using directive or an assembly reference?)。我是 运行 构建过程中的 nuget 恢复。它只是在添加 InternalsVisibleTo 后才开始失败。该解决方案在本地构建得非常好。

我正在使用该属性,以便我可以将某些 类 公开给测试项目而不公开。

我想使用 InternalsVisibleTo 因为它更容易在我的测试项目中管理。

非常感谢任何帮助!

根据 ilyaf 在该问题上的建议 link,我必须在属性上使用完全限定的命名空间,将命名空间作为文件中的 using 语句是不够的。

修复构建:

// This compiles and builds successfully on AppVeyor.
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ProjectA"),
           System.Runtime.CompilerServices.InternalsVisibleTo("ProjectATests")]