InternalsVisibleTo attribute isn't working

后端 未结 19 2474
眼角桃花
眼角桃花 2020-11-27 13:51

I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reas

19条回答
  •  春和景丽
    2020-11-27 13:57

    You are required to generate an new full public key for the assembly and then specify the attribute to assembly.

    [assembly: InternalsVisibleTo("assemblyname,
    PublicKey="Full Public Key")]
    

    Follow the below MSDN steps to generate new full public key for the assembly from visual studio.

    To add a Get Assembly Public Key item to the Tools menu

    In Visual Studio, click External Tools on the Tools menu.

    In the External Tools dialog box, click Add and enter Get Assembly Public Key in the Title box.

    Fill the Command box by browsing to sn.exe. It is typically installed at the following location: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0a\Bin\x64\sn.exe.

    In the Arguments box, type the following (case sensitive): -Tp $(TargetPath). Select the Use Output window check box.

    Click OK. The new command is added to the Tools menu.

    Whenever you need the Public Key Token of the assembly you are developing, click the Get Assembly Public Key command on the Tools menu, and the public key token appears in the Output window.

提交回复
热议问题