I have two projects:
“TestA” project config:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).Abca</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(AssemblyName).Abca</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
and code is:
namespace TestA
{
internal class MyClass
{
public void Hello()
{
}
}
}.
“TestB” project config:
Test.Abca
namespace Test.Abca
{
using TestA;
internal class Class1
{
internal void Foo()
{
MyClass myClass =new MyClass();//'MyClass' is inaccessible due to its protection level
}
}
}
I added the TestA reference to Test.Abca but got an error when using the code:
error CS0122: ‘MyClass’ is inaccessible due to its protection level
I tried improving the InternalsVisibleTo setting to various types but it didn’t work, it only worked when sure with the name “Test.Abca”. This is something I do not want.
What I want is to be used for many projects named like “Test.***”.