c# - 从 .csproj 文件生成 AssemblyInfo 时如何定义多个友元程序集?

标签 c# friend assemblyinfo internalsvisibleto

我想定义几个友元集。 手动编辑 AssemblyInfo 文件时很容易做到这一点:

[assembly:InternalsVisibleTo("Friend1a")]
[assembly:InternalsVisibleTo("Friend1b")]

[assembly:InternalsVisibleTo("Friend2a"), 
      InternalsVisibleTo("Friend2b")]

但是,我的 AssemblyInfo 文件是由 MSBuild 任务.csproj 文件生成的。在这种情况下,我可以添加一个 InternalsVisibleTo 属性,但不能添加多个。

<AssemblyInfo CodeLanguage="CS" OutputFile="$(AssemblyInfoFile)"  AssemblyVersion="$(Version)" InternalsVisibleTo = "Friend1a"/>

如何在我的 .csproj 文件中定义多个友元程序集?

最佳答案

您可以在.csproj 中添加多个友好程序集。文件通过 AssemblyAttribute .将以下代码放在根标记内:

<ItemGroup> <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> <_Parameter1>Friend1</_Parameter1> </AssemblyAttribute> <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> <_Parameter1>Friend2</_Parameter1> </AssemblyAttribute> </ItemGroup>

关于c# - 从 .csproj 文件生成 AssemblyInfo 时如何定义多个友元程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39470255/

相关文章:

c# - $(this) 在 C# 中等效

c# - 使用 ManualResetEventSlim 而不是 ManualResetEvent 的最短等待时间是多少?

msbuild - 版本控制 CommonAssemblyInfo.cs 和 MSBuild

javascript - 客户端本地化

c# - 如何从一个 View 中切换 View ?

c++ - 友元函数

c++ - friend 功能和 friend 类有什么区别?

C++ - 错误 : 'function' was not declared in this scope

.net - 如何管理存储在SVN中的AssemblyInfo.cs以及每次构建时的更改

c# - 使用 Linq-to-Sql 表达式生成 SQL 子句