Skip to content

Commit

Permalink
Merge pull request #7 from thomaslevesque/disable-for-net50sdk
Browse files Browse the repository at this point in the history
Disable for .NET 5.0 SDK
  • Loading branch information
thomaslevesque authored Feb 27, 2022
2 parents 9f59340 + 28152e6 commit 6f2f7b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion InternalsVisibleTo.MSBuild.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>InternalsVisibleTo.MSBuild</id>
<version>1.0.5</version>
<version>1.1.0</version>
<description>Enables declaring 'InternalsVisibleTo' items in a .NET project file, rather than declaring them to an AssemblyInfo.cs file.</description>
<authors>Thomas Levesque</authors>
<projectUrl>https://github.com/thomaslevesque/InternalsVisibleTo.MSBuild</projectUrl>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Enables declaring `InternalsVisibleTo` items in a .NET project file, rather than declaring them in an AssemblyInfo.cs file.

**IMPORTANT: starting with .NET 5.0, the SDK [already provides support for this](https://github.com/dotnet/sdk/pull/3439). You don't need this package if you're using the .NET 5.0 SDK or later.**

## How to use

1. Install the `InternalsVisibleTo.MSBuild` NuGet package.
Expand Down
11 changes: 9 additions & 2 deletions build/InternalsVisibleTo.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<MSBuild_16_5_0_OrGreater>false</MSBuild_16_5_0_OrGreater>
<MSBuild_16_5_0_OrGreater Condition="$([System.Version]::Parse('$(MSBuildVersion)').CompareTo($([System.Version]::Parse('16.5.0')))) &gt;= 0">true</MSBuild_16_5_0_OrGreater>
<SdkSupportsInternalsVisibleTo>false</SdkSupportsInternalsVisibleTo>
<SdkSupportsInternalsVisibleTo Condition="'$(MSBuild_16_5_0_OrGreater)' == 'true' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '5.0.0'))">true</SdkSupportsInternalsVisibleTo>
</PropertyGroup>

<Target Name="AddInternalsVisibleTo" BeforeTargets="BeforeCompile">

<ItemGroup Condition="@(InternalsVisibleTo->Count()) &gt; 0">
<ItemGroup Condition="@(InternalsVisibleTo->Count()) &gt; 0 and '$(SdkSupportsInternalsVisibleTo)' == 'false'">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>%(InternalsVisibleTo.Identity)</_Parameter1>
<_Parameter1_TypeName>System.String</_Parameter1_TypeName>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) &gt; 0">
<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) &gt; 0 and '$(SdkSupportsInternalsVisibleTo)' == 'false'">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(AssemblyName)%(InternalsVisibleToSuffix.Identity)</_Parameter1>
<_Parameter1_TypeName>System.String</_Parameter1_TypeName>
</AssemblyAttribute>
</ItemGroup>

<Warning Condition="'$(SdkSupportsInternalsVisibleTo)' == 'true'"
Text="Starting with version 5.0, the .NET SDK has built-in support for InternalsVisibleTo. The functionality provided by the InternalsVisibleTo.MSBuild package has been disabled to avoid conflicts. You should uninstall this package; note that with the .NET SDK feature, the public key is specified in a separate 'Key' attribute, instead of being appended to the assembly name in the 'Include' attribute." />

</Target>

</Project>

0 comments on commit 6f2f7b6

Please sign in to comment.