Skip to content

Commit afbb379

Browse files
committed
Add support for @(InternalsVisibleTo) items that turn into assembly attributes
Given that `InternalsVisibleTo` (IVT) is such a common assembly-level attribute, this adds support for specifying it directly via simple items, such as: ``` <ItemGroup> <InternalsVisibleTo Include="MyLibrary.Tests" /> </ItemGroup> ``` Optionally, a `Key` metadata can be specified to provide a strong-named IVT: ``` <ItemGroup> <InternalsVisibleTo Include="MyLibrary.Tests" Key="PUBLIC_KEY" /> </ItemGroup> ``` The targets will also use automatically a `$(PublicKey)` if available and no `%(Key)` metadata override is found. Otherwise, it will default to an IVT without a key. This also avoids having to learn the `_Parameter1` syntax in `AssemblyAttribute` elements, and is more similar to the way other higher-level properties like `AssemblyTitle` or `Product` are also turned into assembly attributes. To turn off this feature, set `$(GenerateInternalsVisibleToAttributes)` to `false`. Partially fixes #3166
1 parent 095fe9b commit afbb379

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.GenerateAssemblyInfo.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Copyright (c) .NET Foundation. All rights reserved.
3434
<GenerateAssemblyVersionAttribute Condition="'$(GenerateAssemblyVersionAttribute)' == ''">true</GenerateAssemblyVersionAttribute>
3535
<GenerateNeutralResourcesLanguageAttribute Condition="'$(GenerateNeutralResourcesLanguageAttribute)' == ''">true</GenerateNeutralResourcesLanguageAttribute>
3636
<IncludeSourceRevisionInInformationalVersion Condition="'$(IncludeSourceRevisionInInformationalVersion)' == ''">true</IncludeSourceRevisionInInformationalVersion>
37+
<GenerateInternalsVisibleToAttributes Condition="'$(GenerateInternalsVisibleToAttributes)' == ''">true</GenerateInternalsVisibleToAttributes>
3738
</PropertyGroup>
3839

3940
<!--
@@ -94,6 +95,11 @@ Copyright (c) .NET Foundation. All rights reserved.
9495
<AssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
9596
<_Parameter1>$(NeutralLanguage)</_Parameter1>
9697
</AssemblyAttribute>
98+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo" Condition="%(InternalsVisibleTo.Identity) != '' and '$(GenerateInternalsVisibleToAttributes)' == 'true'">
99+
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' != ''">%(InternalsVisibleTo.Identity), PublicKey=%(InternalsVisibleTo.Key)</_Parameter1>
100+
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' != ''">%(InternalsVisibleTo.Identity), PublicKey=$(PublicKey)</_Parameter1>
101+
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' == ''">%(InternalsVisibleTo.Identity)</_Parameter1>
102+
</AssemblyAttribute>
97103
</ItemGroup>
98104
</Target>
99105

0 commit comments

Comments
 (0)