Visual Studio 2017 and the new .csproj InternalsVisibleTo

若如初见. 提交于 2019-12-03 05:32:14

问题


Where do I put InternalsVisibleTo from AssemblyInfo in the new Visual Studio 2017 .csproj project file?


回答1:


To clarify Hans Passant's comment above, you simply have to add InternalsVisibleTo to any cs file in your project. For example, I created an AssemblyInfo.cs file in the root of the project and then added the following content (only):

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=<ADD_KEY_HERE>")]



回答2:


Just in case anyone would like to put InternalsVisibleTo within a .csproj file instead of AssemblyInfo.cs (a possible scenario is to have a naming convention between a project under test and a test project), you can do it like this:

<ItemGroup>
    <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
      <_Parameter1>$(MSBuildProjectName).Test</_Parameter1>
    </AssemblyAttribute>
</ItemGroup>

Having this the following code will be generated

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("MyProject.Test")]

inside auto-generated AssemblyInfo.cs (e.g. for Debug configuration and .NET Standard 2.0 target)

/obj/Debug/netstandard2.0/MyProject.AssemblyInfo.cs


来源:https://stackoverflow.com/questions/42810705/visual-studio-2017-and-the-new-csproj-internalsvisibleto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!