Skip to content

Commit 096700a

Browse files
Fix InternalsVisibleTo for versioned assemblies (#4581) (#4584)
This commit fixes the inclusion of InternalsVisibleToAttributes for versioned assemblies. Directory.Build.Targets defines an AssemblyInfos target that writes InternalsVisibleTo elements for friend assemblies and versioned friend assemblies, based on the InternalsVisibleTo elements in the target csproj and the version being built. This worked fine when built from Rider IDE (and likely Visual Studio too) due to the way in which MsBuild is invoked from IDE, but did not work as intended when built from the commandline with the build script, which calls dotnet build; The Nest InternalsVisibleTo was correctly written, but none of the InternalsVisibleTo for generated Elasticsearch.Net assemblies were. Looking at the binarylog for MsBuild with the Structured Log Viewer indicated that the task was working as expected from the command line and \obj\$(Configuration\AssemblyInfo.cs generated file was written correctly, but inspection of the file revealed that the InternalsVisibleTo attributes were in fact not generated correctly. In researching friend assemblies, https://docs.microsoft.com/en-us/dotnet/standard/assembly/friend notes the following > When you compile an assembly like AssemblyB that will access internal types or internal members of another assembly like Assembly A, you must explicitly specify the name of the output file (.exe or .dll) by using the -out compiler option. This is required because the compiler has not yet generated the name for the assembly it is building at the time it is binding to external references. The build script does not pass an output path, relying on the convention of output going to /bin/$(Configuration)/$(TargetFramework)/. When the IDE builds projects, it explicitly passes an output path. In summary, the fix to allow InternalsVisibleTo to work as expected from the commandline is to explicitly pass an output path. This is done for all projects by adding <OutDir>bin/$(Configuration)/$(TargetFramework)/</OutDir> to Directory.Build.Targets. Fixes #4538 Co-authored-by: Russ Cam <[email protected]>
1 parent 033349e commit 096700a

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ project.lock.json
8484
/src/.vs/restore.dg
8585
# temporary location for doc generation
8686
docs-temp
87+
*.binlog

Directory.Build.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AssemblyOriginatorKeyFile>$(SolutionRoot)\build\keys\keypair.snk</AssemblyOriginatorKeyFile>
66
</PropertyGroup>
77
<PropertyGroup Condition="$(IsPackable) == True">
8-
8+
<OutDir>bin/$(Configuration)/$(TargetFramework)/</OutDir>
99
<NoWarn>1591,1572,1571,1573,1587,1570,NU5048,</NoWarn>
1010
<Prefer32Bit>false</Prefer32Bit>
1111
<DebugSymbols>true</DebugSymbols>
@@ -23,8 +23,7 @@
2323
>
2424
<PropertyGroup>
2525
<ExposedAssembly>%(InternalsVisibleTo.Identity)</ExposedAssembly>
26-
<VersionNamespaced>$(ExposedAssembly.Replace("Nest","Nest$(MajorVersion)").Replace("Elasticsearch.Net","Elasticsearch.Net$(MajorVersion
27-
)"))</VersionNamespaced>
26+
<VersionNamespaced>$(ExposedAssembly.Replace("Nest", "Nest$(MajorVersion)").Replace("Elasticsearch.Net","Elasticsearch.Net$(MajorVersion)"))</VersionNamespaced>
2827
</PropertyGroup>
2928
<ItemGroup>
3029
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">

build/scripts/Versioning.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ module Versioning =
164164
| true -> validate dll name
165165
| _ -> failwithf "Attempted to verify signature of %s but it was not found!" dll
166166

167-
let private assemblyRewriter = "assembly-rewriter"
168-
169167
let BuiltArtifacts (version: AnchoredVersion) =
170168
let packages =
171169
let allPackages = !! "build/output/_packages/*.nupkg" |> Seq.toList

0 commit comments

Comments
 (0)