Search code examples
c#.net.net-coreassemblyinfoproject-settings

Programmatically access metadata from project file


In VS2019 / .NET Core 3.0, the project metadata is saved in the project file:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
    <Authors>.....</Authors>
    <Description>.....</Description>
    <NeutralLanguage>.....</NeutralLanguage>
    <Copyright>.....</Copyright>
    <StartupObject>.....</StartupObject>
    <ApplicationIcon>.....</ApplicationIcon>
    <Company>.....</Company>
    <PackageTags>.....</PackageTags>
    <PackageReleaseNotes>.....</PackageReleaseNotes>
    <PackageProjectUrl>.....</PackageProjectUrl>
    <PackageIconUrl>.....</PackageIconUrl>
    <RepositoryUrl>.....</RepositoryUrl>
    <RepositoryType>.....</RepositoryType>
</PropertyGroup>

Some of these vales can be accessed via version or custom attributes. But some new values like Authors, PackageTags, ... are not yet part of the AssemblyInfo handling.

My question is: how can I access these values from within my application?


Solution

  • Those properties are related to the target NuGet package if you publish one. They won't be embedded into your application, so you cannot access them.

    For more info, read the Additions to the csproj format for .NET Core documentation, especially the NuGet metadata properties topic.

    The following is the list of properties that are used as inputs to the packing process when using the dotnet pack command or the Pack MSBuild target that is part of the SDK.

    • Authors
    • PackageTags
    • ...