Project InternalsVisibleTo is ignored on build

  • TeamCity: TeamCity Professional 2022.10 (build 116751)
  • MSBuild 2022
  • SDK style csproj files (netstandard2.0)

I'm having a problem where builds keep failing when one of the project in the solution requires access to internal classes of a different project in the same solution. While that class defines a [assembly: InternalsVisibleTo("")] attribute. That is correct because everything works in Visual Studio.

I keep getting the following errors that fail the build

C:\B\a92eea093e3c0317\Framework.Actions.Test\UnitTest1.cs(18,53): error CS0122: 'InternalTestAction<T>' is inaccessible due to its protection level

If I run the exact same MSBuild command that TeamCity uses on the same system these errors don't pop up. 

.\MSBuild.exe C:\B\a92eea093e3c0317\Actions.Framework.sln @C:\T\agentTmp\1.rsp -restore -noLogo -m:1

I'm at a complete loss what can cause this different behaviours.

Comment actions Permalink

The error is produced by a different step then I thought.

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe 

the csc.exe seems to produce the error mentioned above. What I could quickly find is that you need to provide /out <assembly name> parameter. That one seems to be provided in the parameters given to the csc.exe. So still unsure why it produces the error. Also couldn't reproduce the command manually yet to check if it would produce the same result.

Comment actions Permalink

Found the underlying cause. The AssemblyInfo.cs file is being ignored during the build (MSBuild). This is the default behaviour for SDK style csproj files.

But we have the option


set in that csproj file that should cause the build to use the old AssemblyInfo.cs file while building. Visual Studio does, but the MSBuild command used by TeamCity apparently doesn't? This seems like a bug in the way TeamCity handles SDK style csproj files. 

At the moment we use the AssemblyInfo.cs project file to also inject version information of the build. So we really would like to keep using it. 

For people that don't have any use of the AssemblyInfo.cs file but run into the same problem you can move the [assemby: InternalsVisibleTo()] attribute to any code file other then AssemblyInfo.cs or you can remove the <GenerateAssemblyInfo> line from your csproj file and add the following to enable internals visible to again.

    <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">

Just replace $(AssemblyName).Text.dll for your friendly dll name





Please sign in to leave a comment.