Search code examples
c#wpf.net-6.0csprojgitversion

GitVersion: Copyright attribute missing when publishing a single file with *GenerateAssemblyInfo* set to *false*


I am using GitVersion in my WPF-project. When publishing my app I use profile setting Produce single file which I want to stick to. Publish only runs successfully if I set im my .csproj-file:

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
       <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
   </PropertyGroup>
</Project>

I also have set the Copyright information in my .csproj-file:

<Copyright>Copyright © ...</Copyright>

  • With GenerateAssemblyInfo set to true I can read the Copyright attribute in my code by reflection:

     var copyRightAttribute = (AssemblyCopyrightAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyCopyrightAttribute));
    

    Also in file-details it is visible:

    file-details with copyright


  • With GenerateAssemblyInfo set to false publishing the Singe file runs successfully but Copyright is missing in code and in file details.

How can I have all at the same time?

  1. Use GitVersion AND
  2. publish a Single file AND
  3. access Copyright attribute in code AND
  4. see Copyright in file-details

Solution

  • When you disable automatic AssemblyInfo generation,
    then you will need to include an AssemblyInfo.cs file yourself into your project, holding the AssemblyCopyrightAttribute and others.

    The ones in the .csproj file will not be considered anymore when it contains an <GenerateAssemblyInfo>false</GenerateAssemblyInfo>.

    Note that this also includes the version numbers and more.


    An AssemblyInfo.cs example:

    using System.Reflection;
    
    [assembly: AssemblyCopyright("Your Copyright Goes Here")]
    
    [assembly: AssemblyTitle("Your Title")]
    [assembly: AssemblyDescription("Your Description")]
    
    [assembly: AssemblyVersion("1.0.0")]
    [assembly: AssemblyFileVersion("1.0.0")]
    [assembly: AssemblyInformationalVersion("1.0.0")]