Skip to main content

🐞 GitVersioning: 'ThisAssembly' Is Inaccessible Due to Its Protection Level

·202 words·1 min
Hong Konger.

😨 Problem #

After I installed the Nerdbank.GitVersioning Nuget package in my .NET MVC app, the following error came out when I want to get the version using ThisAssembly.AssemblyInformationalVersion:

error CS0122: 'ThisAssembly' is inaccessible due to its protection level

I tried to install the package across all the projects in the same solution. It didn’t work.

I tried to uninstall and re-ininstall the package. It didn’t work.

πŸ˜€ Solution #

.csproj #

Turns out there is something missing in my .csproj file. I missed an <Import> tag at the end of the file, just before the </Target> tag:

<Import Project="..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets')" />

And in the EnsureNuGetPackageBuildImports target, add the following line:

<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.1.91\build\Nerdbank.GitVersioning.targets'))" />

In addition, the 1st <PropertyGroup> should contain a pair of NuGetPackageImportStamp tag:


AssemblyInfo.cs #

I also removed the following lines in Properties/AssemblyInfo.cs:

[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]

version.json #

At the root directory of the project, I added a version.json file with the following content:

  "$schema": "",
  "version": "1.0.0"

After that, ThisAssembly is back and I can read the git version info successfully.

πŸ”— references: #
πŸ–Ό cover image: Grace Hopper’s operational logbook for the Harvard Mark II computer #


A Tale of Two Caches: Redis and the cache helper
·884 words·5 mins
A note on how to add Redis and the cache helper to a .NET core Mvc app.
Documentation Makes Easy With MkDocs and GitLab Pages
·1045 words·5 mins
A guide to build a static website using MkDocs and deploy it to GitLab Pages.
A Note on SSL Certificate
·566 words·3 mins
This is a note about the Linkedin learning course SSL Certificates for Web Developers.