๐จ 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:
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
AssemblyInfo.cs
I also removed the following lines in Properties/AssemblyInfo.cs
:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
version.json
At the root directory of the project, I added a version.json
file with the following content:
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0.0"
}
After that, ThisAssembly
is back and I can read the git version info successfully.
๐ references:
- https://github.com/dotnet/Nerdbank.GitVersioning/blob/master/doc/dotnet.md
- https://github.com/dotnet/Nerdbank.GitVersioning/issues/449
- https://github.com/dotnet/Nerdbank.GitVersioning/issues/404
๐ผ cover image:
Grace Hopperโs operational logbook for the Harvard Mark II computer
Top comments (0)