如何在.NET Core 1.1中的程序集上使用自定义属性 [英] How to use a custom attribute on an assembly in .NET Core 1.1

查看:75
本文介绍了如何在.NET Core 1.1中的程序集上使用自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我发现这篇文章关于在以下位置检索自定义属性程序集,我不确定如何向.NET Core 1.1中的程序集添加自定义属性。在.NET Framework中,我将执行以下操作:

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")]

但是我在Visual Studio中的netcore1.1项目没有AssemblyInfo.cs。在哪里可以为程序集声明自定义属性?我可以在.csproj文件中放一些东西吗?

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?

推荐答案

您始终可以创建一个新的 AssemblyInfo .cs 文件或任何其他 .cs 文件执行相同的操作。

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

但是您还可以使用新的自动生成的装配体信息机制。您可以将其添加到您的 csproj 文件中,用自定义类型名称替换 Include 属性值属性:

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>

这篇关于如何在.NET Core 1.1中的程序集上使用自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆