View on GitHub

ThisAssembly

Exposes project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.

Icon ThisAssembly

Version Downloads License Build

Exposes project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.

The main generated entry point type is ThisAssembly in the global namespace, and is declared as partial so you can extend it too with manually created members.

Each package in turn extends this partial class too to add their own constants.

The ThisAssembly meta-package includes all the other packages for convenience.

NOTE: as of .NET 5.0 RC1, only C# is supported for source generators so even if the generators here can emit proper VB and F#, no code will be generated (yet) for those languages. When support is introduced for those languages, things will Just Work without the need to update these packages.

NOTE: if intellisense isn’t working properly, try closing and reopening Visual Studio. If that doesn’t work, please set the $(IncludeSourceGeneratorIntellisenseFix) property to true in your project. This is a temporary workaround for a Roslyn issue that should be solved by the final release of .NET5.

ThisAssembly.AssemblyInfo

Version Downloads

This package generates a static ThisAssembly.Info class with public constants exposing the following attribute values generated by default for SDK style projects:

If your project includes these attributes by other means, they will still be emitted properly on the ThisAssembly.Info class.

ThisAssembly.Constants

Version Downloads

This package generates a static ThisAssembly.Constants class with public constants for @(Constant) MSBuild items in the project.

In addition to arbitrary constants via <Constant ...>, it’s quite useful in particular in test projects, to generate constants for files in the project, so there’s also a shorthand for those:

  <ItemGroup>
    <FileConstant Include="@(Content)" />
  <ItemGroup>

Which results in:

ThisAssembly.Metadata

Version Downloads

This package provides a static ThisAssembly.Metadata class with public constants exposing each [System.Reflection.AssemblyMetadata(..)] defined for the project.

For an attribute declared (i.e. in AssemblyInfo.cs) like:

  [assembly: System.Reflection.AssemblyMetadataAttribute("Foo", "Bar")]

A corresponding ThisAssembly.Metadata.Foo constant with the value Bar is provided. The metadata attribute can alternatively be declared using MSBuild syntax in the project (for .NET 5.0+ projects that have built-in support for @(AssemblyMetadata) items):

    <ItemGroup>
      <AssemblyMetadata Include="Foo" Value="Bar" />
    </ItemGroup>

Generated code:

C#:

  partial class ThisAssembly
  {
      public static partial class Metadata
      {
          public const string Foo = "Bar";
      }
  }

VB:

  Namespace Global
    Partial Class ThisAssembly
          Partial Class Metadata
              Public Const Foo = "Bar"
          End Class
      End Class
  End Namespace

F#:

  module internal ThisAssembly

  module public Metadata =
      [<Literal>]
      let public Foo = @"Bar"

ThisAssembly.Project

Version Downloads

This package generates a static ThisAssembly.Project class with public constants exposing project properties that have been opted into this mechanism by adding them as ThisAssemblyProject MSBuild items in project file, such as:

  <PropertyGroup>
    <Foo>Bar</Foo>
  </PropertyGroup>
  <ItemGroup>
    <ThisAssemblyProject Include="Foo" />
  </ItemGroup>

Generated code:

C#:

  partial class ThisAssembly
  {
      public static partial class Project
      {
          public const string Foo = "Bar";
      }
  }

VB:

  Namespace Global
    Partial Class ThisAssembly
          Partial Class Project
              Public Const Foo = "Bar"
          End Class
      End Class
  End Namespace

F#:

  module internal ThisAssembly

  module public Project =
      [<Literal>]
      let public Foo = @"Bar"

ThisAssembly.Strings

Version Downloads

This package generates a static ThisAssembly.Strings class with public constants exposing string resources in .resx files or methods with the right number of parameters for strings that use formatting parameters.

In addition, it groups constants and methods in nested classes according to an optional underscore separator to organize strings. For example, User_InvalidCredentials can be accessed with ThisAssembly.Strings.User.InvalidCredentials if it contains a simple string, or as a method with the right number of parametres if its value has a format string.

Given the following Resx file:

Name Value Comment    
Infrastructure_MissingService Service {0} is required. For logging only!    
Shopping_NoShipping We cannot ship {0} to {1}.      
Shopping_OutOfStock Product is out of stock at this time.      

The following code would be generated:

partial class ThisAssembly
{
    public static partial class Strings
    {
        public static partial class Infrastructure
        {
            /// <summary>
            /// For logging only!
            /// => "Service {0} is required."
            /// </summary>
            public static string MissingService(object arg0)
                => string.Format(CultureInfo.CurrentCulture, 
                    Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("MissingService"), 
                    arg0);
        }

        public static partial class Shopping
        {
            /// <summary>
            /// => "We cannot ship {0} to {1}."
            /// </summary>
            public static string NoShipping(object arg0, object arg1)
                => string.Format(CultureInfo.CurrentCulture, 
                    Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("NoShipping"), 
                    arg0, arg1);

            /// <summary>
            /// => "Product is out of stock at this time."
            /// </summary>
            public static string OutOfStock
                => Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("OutOfStock");
        }
    }
}

Dogfooding

CI Version GH CI Status AzDO CI Status

We also produce CI packages from branches and pull requests so you can dogfood builds as quickly as they are produced.

The CI feed is https://pkg.kzu.io/index.json.

The versioning scheme for packages is: