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:
- 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?
- Use GitVersion AND
- publish a Single file AND
- access Copyright attribute in code AND
- see Copyright in file-details
CodePudding user response:
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")]