Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<GenerateNeutralResourcesLanguageAttribute Condition="'$(GenerateNeutralResourcesLanguageAttribute)' == ''">true</GenerateNeutralResourcesLanguageAttribute>
<GenerateAssemblyMetadataAttributes Condition="'$(GenerateAssemblyMetadataAttributes)' == ''">true</GenerateAssemblyMetadataAttributes>
<IncludeSourceRevisionInInformationalVersion Condition="'$(IncludeSourceRevisionInInformationalVersion)' == ''">true</IncludeSourceRevisionInInformationalVersion>
<GenerateInternalsVisibleToAttributes Condition="'$(GenerateInternalsVisibleToAttributes)' == ''">true</GenerateInternalsVisibleToAttributes>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -95,10 +96,15 @@ Copyright (c) .NET Foundation. All rights reserved.
<AssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo" Condition="%(InternalsVisibleTo.Identity) != '' and '$(GenerateInternalsVisibleToAttributes)' == 'true'">
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' != ''">%(InternalsVisibleTo.Identity), PublicKey=%(InternalsVisibleTo.Key)</_Parameter1>
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' != ''">%(InternalsVisibleTo.Identity), PublicKey=$(PublicKey)</_Parameter1>
<_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == '' and '$(PublicKey)' == ''">%(InternalsVisibleTo.Identity)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadata" Condition="%(AssemblyMetadata.Identity) != '' and '$(GenerateAssemblyMetadataAttributes)' == 'true'">
<_Parameter1>%(AssemblyMetadata.Identity)</_Parameter1>
<_Parameter2>%(AssemblyMetadata.Value)</_Parameter2>
</AssemblyAttribute>
</AssemblyAttribute>
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit.Abstractions;
using Microsoft.NET.TestFramework.ProjectConstruction;
using System.Xml.Linq;
using Xunit.Sdk;

namespace Microsoft.NET.Build.Tests
{
Expand Down Expand Up @@ -348,6 +349,111 @@ BuildCommand BuildProject(string buildNumber)
return command;
}
}

[Fact]
public void It_includes_internals_visible_to()
{
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFramework("netstandard2.0")
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;

project.Root.Add(
new XElement(ns + "ItemGroup",
new XElement(ns + "InternalsVisibleTo",
new XAttribute("Include", "Tests"))));
});

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll");

AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests");
}

[Fact]
public void It_respects_out_out_of_internals_visible_to()
{
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFramework("netstandard2.0")
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;

project.Root.Add(
new XElement(ns + "PropertyGroup",
new XElement(ns + "GenerateInternalsVisibleToAttributes", "false")),
new XElement(ns + "ItemGroup",
new XElement(ns + "InternalsVisibleTo",
new XAttribute("Include", "Tests"))));
});

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll");

Assert.False(AssemblyInfo.Get(assemblyPath).ContainsKey("InternalsVisibleToAttribute"));
}

[Fact]
public void It_includes_internals_visible_to_with_key()
{
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFramework("netstandard2.0")
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;

project.Root.Add(
new XElement(ns + "ItemGroup",
new XElement(ns + "InternalsVisibleTo",
new XAttribute("Include", "Tests"),
new XAttribute("Key", "00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2"))));
});

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll");

AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2");
}

[Fact]
public void It_includes_internals_visible_to_with_project_publickey()
{
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFramework("netstandard2.0")
.WithProjectChanges((path, project) =>
{
var ns = project.Root.Name.Namespace;

project.Root.Add(
new XElement(ns + "PropertyGroup",
new XElement(ns + "PublicKey", "00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2")),
new XElement(ns + "ItemGroup",
new XElement(ns + "InternalsVisibleTo",
new XAttribute("Include", "Tests"))));
});

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll");

AssemblyInfo.Get(assemblyPath)["InternalsVisibleToAttribute"].Should().Be("Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001d3e6bbb36e11ea61ceff6e1022b23dd779fc6230838db2d25a2c7c8433b3fcf86b16c25b281fc3db1027c0675395e7d0548e6add88b6a811962bf958101fa9e243b1618313bee11f5e3b3fefda7b1d1226311b6cc2d07e87ff893ba6890b20082df34a0aac14b605b8be055e81081a626f8c69e9ed4bbaa4eae9f94a35accd2");
}

[Fact]
public void It_includes_assembly_metadata()
Expand All @@ -367,13 +473,10 @@ public void It_includes_assembly_metadata()
new XAttribute("Value", "MetadataValue"))));
});

new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass();

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

var assemblyPath = Path.Combine(buildCommand.GetOutputDirectory("netstandard2.0").FullName, "HelloWorld.dll");
var info = AssemblyInfo.Get(assemblyPath);

AssemblyInfo.Get(assemblyPath)["AssemblyMetadataAttribute"].Should().Be("MetadataKey:MetadataValue");
}
Expand All @@ -398,8 +501,6 @@ public void It_respects_out_out_of_assembly_metadata()
new XAttribute("Value", "MetadataValue"))));
});

new RestoreCommand(Log, testAsset.TestRoot).Execute().Should().Pass();

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand.Execute().Should().Pass();

Expand Down