Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Last active October 18, 2025 13:15
Show Gist options
  • Select an option

  • Save karenpayneoregon/a1997f3c972eaae3e24477979a983912 to your computer and use it in GitHub Desktop.

Select an option

Save karenpayneoregon/a1997f3c972eaae3e24477979a983912 to your computer and use it in GitHub Desktop.
Project copyright

About

Get/set copyright for a project

Instructions

Under project properties, package, general, copyright add the following and modify as needed.

2024-$([System.DateTime]::Now.Year)

Or add the following directly into the project file.

<PropertyGroup>
	<OutputType>Exe</OutputType>
	<TargetFramework>net9.0</TargetFramework>
	<ImplicitUsings>enable</ImplicitUsings>
	<Nullable>disable</Nullable>
	<LangVersion>preview</LangVersion>
	<Copyright>2024-$([System.DateTime]::Now.Year) Karen Payne</Copyright>
</PropertyGroup>

Use Special.GetCopyright() to read the copyright.

/// <summary>
/// Provides utility methods to retrieve assembly metadata such as company, product, copyright, and version information.
/// </summary>
public class Info
{
private static Assembly Assembly => Assembly.GetExecutingAssembly();
public static string GetCopyright()
{
var attr = Assembly
.GetCustomAttribute<AssemblyCopyrightAttribute>();
return attr?.Copyright ?? "No copyright information found.";
}
public static string GetCompany()
{
var attr = Assembly
.GetCustomAttribute<AssemblyCompanyAttribute>();
return attr?.Company ?? "No company information found.";
}
public static string GetProduct()
{
var attr = Assembly
.GetCustomAttribute<AssemblyProductAttribute>();
return attr?.Product ?? "No product information found.";
}
public static Version GetVersion()
{
return Assembly.GetName().Version;
}
}
using System.Reflection;
namespace Your_Namespace;
public class Special
{
public static string GetCopyright()
{
var attr = Assembly
.GetExecutingAssembly()
.GetCustomAttribute<AssemblyCopyrightAttribute>();
return attr?.Copyright ?? "No copyright information found.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment