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

查看:32
本文介绍了如何在 .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天全站免登陆