虽然我发现这篇关于在程序集上检索自定义属性的帖子,但我不确定如何在.NET Core 1.1中为程序集添加自定义属性.在.NET Framework中,我会做类似的事情:
[assembly: AdditionalLocation(@"..\ReadFromHere")]
Run Code Online (Sandbox Code Playgroud)
但我在Visual Studio中的netcore1.1项目没有AssemblyInfo.cs.我在哪里声明程序集的自定义属性?我可以在.csproj文件中放一些东西吗?
Mar*_*ich 18
您始终可以创建新AssemblyInfo.cs
文件或任何其他.cs
文件来执行相同操作.
但是,您也可以使用新的自动生成的程序集信息机制.您可以将其添加到csproj
文件中,将替换Include
属性值的值替换为自定义属性的类型名称:
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>DasMulli.Win32.ServiceUtils.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
当我将库从旧的 .net 框架移动到 .net 标准时,我遇到了这个问题,我设法通过添加曾经存在于 AssemblyInfo.cs 中的非字符串属性来解决该问题。这是我的 .csproj 文件的片段,当运行构建时,我的属性就在那里:
<ItemGroup>
<AssemblyAttribute Include="Xunit.CollectionBehavior">
<_Parameter1>Xunit.CollectionBehavior.CollectionPerAssembly</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
<_Parameter1_TypeName>Xunit.CollectionBehavior.CollectionPerAssembly</_Parameter1_TypeName>
</AssemblyAttribute>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
它已添加到 msbuild 中,如下所述: https: //github.com/dotnet/msbuild/issues/2281 和https://github.com/dotnet/msbuild/blob/main/documentation/Changelog.md#msbuild-16100这个版本。
希望能帮助到你!现在有了这个就好多了。
归档时间: |
|
查看次数: |
2684 次 |
最近记录: |