Assembly Info
Capture build-time variables as compile-time constants in a generated static class. Common properties like Company, Version, and TargetFramework are included automatically.
Add custom values in your project file:
<Project> <PropertyGroup> <TargetFramework>net9.0</TargetFramework> <MyCustomVar>Hello World</MyCustomVar> </PropertyGroup>
<ItemGroup> <ReflectorItem Include="MyReflectorItem" Value="This is a sample value" Visible="false" />
<!-- Capture a build property --> <ReflectorItem Include="PropertyGroupMyCustomVar" Value="$(MyCustomVar)" Visible="false" /> </ItemGroup></Project>This generates:
public static class AssemblyInfo{ public const string Company = "Samples"; public const string Version = "1.0.0"; public const string TargetFramework = "net9.0"; public const string TargetFrameworkVersion = "v9.0"; public const string Platform = "AnyCPU"; public const string MyReflectorItem = "This is a sample value"; public const string PropertyGroupMyCustomVar = "Hello World";}Use it anywhere:
Console.WriteLine($"Version: {AssemblyInfo.Version}");Console.WriteLine($"Custom: {AssemblyInfo.PropertyGroupMyCustomVar}");