Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a custom attribute on an assembly in .NET Core 1.1

While I found this post regarding retrieving a custom attribute on an assembly, I am unsure on how to add a custom attribute to an assembly in .NET Core 1.1. In .NET Framework, I would have done something like:

[assembly: AdditionalLocation(@"..\ReadFromHere")]

But my netcore1.1 projects in Visual Studio do not have an AssemblyInfo.cs. Where would I declare a custom attribute for an assembly? Is there something I can put in the .csproj file?

like image 1000
MVinca Avatar asked Jun 12 '17 14:06

MVinca


2 Answers

You can always create a new AssemblyInfo.cs file or any other .cs file to do the same.

However you can also use the new auto-generated assembly info mechanism. You can add this to your csproj file, replace the value replacing the Include attributes value with the type name of your custom attribute:

<ItemGroup>
  <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
    <_Parameter1>DasMulli.Win32.ServiceUtils.Tests</_Parameter1>
  </AssemblyAttribute>
</ItemGroup>
like image 54
Martin Ullrich Avatar answered Oct 06 '22 19:10

Martin Ullrich


With .NET 5.0, you can use AssemblyMetadata:

<AssemblyMetadata Include="Bar" Value="Baz" />

like image 26
Vadim Peretokin Avatar answered Oct 06 '22 19:10

Vadim Peretokin