-
Notifications
You must be signed in to change notification settings - Fork 0
/
InternalsVisibleTo.htm
76 lines (68 loc) · 3.96 KB
/
InternalsVisibleTo.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>InternalsVisibleTo</title>
</head>
<body><a href="https://github.com/ArsenShnurkov/gentoo-mono-handbook"><img alt="Fork me on GitHub" id="forkme" src="images/forkme.png" align="right" width="100" /></a>
<table><tr><td valign="top">
<h1>InternalsVisibleTo</h1>
</td><td valign="top">
<a href="index.htm">Gentoo Mono Handbook</a>
<br />
MSDN: <a href="https://msdn.microsoft.com/en-US/library/system.runtime.compilerservices.internalsvisibletoattribute%28v=vs.110%29.aspx">en</a>, <a href="https://msdn.microsoft.com/ru-ru/library/system.runtime.compilerservices.internalsvisibletoattribute%28v=vs.110%29.aspx">ru</a>
<br />
<a href="mono.snk.htm">mono.snk - installation and usage</a>
<br />
<a href="how-to-make-signed-assembly.htm">How to make signed assembly?</a>
</td></tr></table>
How many instances of System.Runtime.CompilerServices.InternalsVisibleToAttribute are allowed, only one or several of them?
<a href="https://msdn.microsoft.com/ru-ru/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx">Many (MSDN)</a>
<pre>
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = true,
Inherited = false)]
public sealed class InternalsVisibleToAttribute : Attribute
</pre>
<br />
InternalsVisibleTo attribute can be generated by
<br />
MSBuild.Community.Tasks
<br />
<a href="https://github.com/loresoft/msbuildtasks/blob/master/Source/MSBuild.Community.Tasks/AssemblyInfo.cs#L439-L449">https://github.com/loresoft/msbuildtasks/blob/master/Source/MSBuild.Community.Tasks/AssemblyInfo.cs#L439-L449</a>
<br />
public key can be retrieved with sn pipelined to grep (isn't it easier to encode that logic into separate task? this will not require external tools and their error processing with bash)
<br />
need to check the implementation of internals visible to in that task
<br />
<br />
it is possible to conditionally include files in msbuild project. Conditions can check msbuild properties which are passed to xbuild from command line.
<br />
i.e. /p:SignAssembly=true
<br />
<a href="https://msdn.microsoft.com/en-us/library/7szfhaft.aspx">MSBuild Conditions (MSDN)</a>
<h2>Adding into project</h2>
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")]
<h2>mpt-csproj</h2>
mpt-csproj --inject-InternalsVisibleTo=Newtonsoft.Json.Tests --AssemblyKeyContainerName=mono Newtonsoft.Json.csproj
<br />
mpt-csproj --inject-InternalsVisibleTo=Newtonsoft.Json.Tests --AssemblyOriginatorKeyFile=mono.snk Newtonsoft.Json.csproj
<h2>Links</h2>
<a href="http://stackoverflow.com/questions/8983097/internalsvisibleto-attribute-not-compiling-under-xbuild-mono-2-10-6-but-works">http://stackoverflow.com/questions/8983097/internalsvisibleto-attribute-not-compiling-under-xbuild-mono-2-10-6-but-works</a>
<br />
without strongly-naming the assemblies and the error doesn't occur if they're not.
<br />
<a href="https://github.com/JamesNK/Newtonsoft.Json/issues/353">https://github.com/JamesNK/Newtonsoft.Json/issues/353</a>
<br />
Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
<br />
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests")]
<br />
<br />
Properties/AssemblyInfo.cs(92,12): error CS1726: Friend assembly reference `Newtonsoft.Json.Tests' is invalid. Strong named assemblies must specify a public key in their InternalsVisibleTo declarations
<br />
<br />
Properties/AssemblyInfo.cs(92,12): error CS0117: `System.Runtime.CompilerServices.InternalsVisibleToAttribute' does not contain a definition for `PublicKey'
<br />
^^ that's because PublicKey should be inside the string, not as a separate attribute
</body>
</html>