Skip to content

Commit

Permalink
Merge pull request #2028 from thomaslevesque/internals-visibleto-in-p…
Browse files Browse the repository at this point in the history
…roject-file

Update the docs to show how to specify InternalsVisibleTo in the project file
  • Loading branch information
blairconrad committed May 22, 2024
2 parents 6e18673 + d23e83c commit cc27472
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
46 changes: 36 additions & 10 deletions docs/how-to-fake-internal-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,45 @@ test, not your test-assembly that needs this attribute.

### Unsigned assemblies

If your assembly is not signed with a strong name it's as easy as
adding the equivalent of the following to your AssemblyInfo.cs/vb
file:

```csharp
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
If your assembly is not signed with a strong name, it's as easy as
adding the following to your project file (assuming you're using
.NET 5 SDK or higher):

```xml
<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
```

If you're using an older SDK, you can add this to your
AssemblyInfo.cs/vb file instead:

=== "C#"
```csharp
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
```
=== "VB"
```vb
<Assembly:InternalsVisibleTo("DynamicProxyGenAssembly2")>
```

### Signed assemblies

For signed assemblies you have to specify the strong name of the
proxy-generating assembly:
For signed assemblies, you have to specify the public key of the
proxy-generating assembly in your project file:

```csharp
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
```xml
<ItemGroup>
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />
</ItemGroup>
```

Or, if using an older SDK, in your AssemblyInfo.cs/vb file:
=== "C#"
```csharp
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
```
=== "VB"
```vb
<Assembly:InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")>
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ markdown_extensions:
check_paths: true
dedent_subsections: true
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.tilde

nav:
Expand Down

0 comments on commit cc27472

Please sign in to comment.