Reputation: 3991
My .csproj
file contains:
...
<PackageId>MyProject</PackageId>
<Version>1.0.0</Version>
...
How can I access that from my project's code?
Upvotes: 5
Views: 2463
Reputation: 2242
To access version and more general properties of your project use:
GetCustomAttribute<T>()
Use AssemblyInformationalVersionAttribute
as type T to retrieve the Version property.
For other values for T, see the attributes listed on https://learn.microsoft.com/en-us/dotnet/api/system.reflection?view=netcore-2.0
Example:
typeof(Startup).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion
Upvotes: 8