How to define multiple friend assemblies when generating AssemblyInfo from .csproj file?
Asked Answered
I

2

6

I would like to define several friend assemblies. It is easy to do so when editing the AssemblyInfo file manually:

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

or

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

However my AssemblyInfo file is generated by an MSBuild task from the .csproj file. In this case, I can add one InternalsVisibleTo attribute, but not several.

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

How can I define multiple friend assemblies in my .csproj file?

Io answered 13/9, 2016 at 12:34 Comment(0)
A
10

You can add multiple friendly assemblies in .csproj files via AssemblyAttribute. Place the following code inside a root tag:

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

Arcanum answered 25/6, 2018 at 6:18 Comment(0)
C
1

Just add them in another file. 'ExtraAssemblyInfo.cs'. There is nothing special code-wise about the AssemblyInfo file it's just a long standing convention.

Causation answered 13/9, 2016 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.