• Stars
    star
    418
  • Rank 103,620 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 to add their own nestes types and members.

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

NOTE: for now, ThisAssembly only generates C# code.

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:

  • AssemblyConfigurationAttribute

  • AssemblyCompanyAttribute

  • AssemblyTitleAttribute

  • AssemblyDescriptionAttribute

  • AssemblyProductAttribute

  • AssemblyCopyrightAttribute

  • AssemblyVersionAttribute

  • AssemblyInformationalVersionAttribute

  • AssemblyFileVersionAttribute

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.

  <ItemGroup>
    <Constant Include="Foo.Bar" Value="Baz" Comment="Yay!" />
    <Constant Include="Foo.Hello" Value="World" Comment="Comments make everything better 😍" />
  </ItemGroup>

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.Git

Version Downloads

This package generates a static ThisAssembly.Git class with constants for the following Git properties from the current project:

  • Commit
  • Sha (first 9 chars from Commit)
  • Root (normalized to forward slashes)
  • Url (if PublishRepositoryUrl=true)
  • Branch (from CI environment variables)

This package relies on your project's installed Microsoft.SourceLink.* package reference according to your specific Git-based source control server (such as GitHub, Azure DevOps, BitBucket, etc).

The Branch property is populated from environment variables provided by the currently supported CI systems: GitHub Actions, Azure DevOps, AppVeyor, TeamCity, Travis CI, Circle CI, GitLab CI, Buddy, and Jenkins.

Whenever the CI system provides a pull request number, the branch name is pr[NUMBER], such as pr123. This makes it easy to use it as a semver metadata label.

Note: by default, the values of these constants are populated during "real" builds (that is, not IDE/design-time builds used to populate intellisense). This is to avoid negatively affecting the editor's performance. This means, however, that the properties will seem to always be empty when inspecting them in the IDE (although never at run-time). If you want to force population of these values for design-time builds, set the EnableSourceControlManagerQueries property to true. This property is defined and documented by dotnet/sourcelink.

At the MSBuild level, targets can take a dependency on the provided InitializeGitInformation target, which sets the equivalent properties named:

  • RepositoryCommit
  • RepositorySha
  • RepositoryRoot
  • RepositoryUrl
  • RepositoryBranch

The names of these properties were chosen on purpose to match the properties used by nuget pack and nugetizer to populate the relevant package metadata.

So if you have a GitHub repository, installing these three packages will ensure you have the proper metadata out of the box and the simplest packaging experience possible:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.GitHub" />
    <PackageReference Include="ThisAssembly.Git" />
    <PackageReference Include="NuGetizer" />
  </ItemGroup>
</Project>

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>

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 ProjectProperty MSBuild items in the project file, such as:

  <PropertyGroup>
    <!-- Some arbitrary MSBuild property declared somewhere -->
    <Foo>Bar</Foo>
  </PropertyGroup>
  <ItemGroup>
    <!-- Opt-in to emitting that property value as a constant in ThisAssembly.Project -->
    <ProjectProperty Include="Foo" />
  </ItemGroup>

ThisAssembly.Resources

Version Downloads

This package generates a static ThisAssembly.Resources class with public properties exposing shortcuts to retrieve the contents of embedded resources.

This package generates a static ThisAssembly.Resources class with public properties exposing typed APIs to retrieve the contents of embedded resources.

  <ItemGroup>
    <EmbeddedResource Include="Content/Docs/License.md" />
  </ItemGroup>

Since markdown files are text files, the API will expose a Text property property for it that will read its content once and cache it:

The $(EmbeddedResourceStringExtensions) MSBuild property allows customizing which file extensions get treated as text files. By default, it's defined as:

  <PropertyGroup>
    <EmbeddedResourceStringExtensions>.txt|.cs|.sql|.json|.md</EmbeddedResourceStringExtensions>
  </PropertyGroup>

You can append additional file extensions to this list, or override it completely. The list must be pipe-separated.

You can always use the provided GetStream and GetBytes for more advanced scenarios (or for non-text resources).

Optionally, you can specify the Kind metadata for a specific EmbeddedResource you want treated as a text file:

    <EmbeddedResource Include="query.kql" Kind="Text" />

You can also add a Comment item metadata attribute, which will be used as the <summary> XML doc for the generated member.

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 Build

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:

  • PR builds: 42.42.42-pr[NUMBER]
  • Branch builds: 42.42.42-[BRANCH].[COMMITS]

Sponsors

Clarius Org Christian Findlay C. Augusto Proiete Kirill Osenkov MFB Technologies, Inc. SandRock Eric C Andy Gocke

Sponsor this project Β 

Learn more about GitHub Sponsors

More Repositories

1

moq

The most popular and friendly mocking framework for .NET
C#
5,709
star
2

GitInfo

Git and SemVer Info from MSBuild, C# and VB
Pascal
513
star
3

SmallSharp

Create, edit and run multiple C# top-level programs in the same project by just selecting the startup program from the start button.
C#
279
star
4

nugetizer

A simple to understand packing model for authoring NuGet packages
C#
253
star
5

avatar

A modern compile-time generated interception/proxy library
C#
139
star
6

NuDoq

A standalone API to read .NET XML documentation files and optionally augment it with reflection information.
C#
105
star
7

dotnet-file

Download, update and sync loose files from URLs
C#
52
star
8

dotnet-vs

A global tool for managing Visual Studio installations
C#
49
star
9

DependencyInjection.Attributed

Provides compile-time discovery and code generation of service registrations from attributed types
C#
36
star
10

CloudActors

An opinionated, simplified and uniform Cloud Native actors' library that integrates with Microsoft Orleans.
C#
33
star
11

RxFree

An ultra-lightweight Rx source-only nuget to avoid depending on the full System.Reactive for IObservable<T> producers
C#
32
star
12

SponsorLink

SponsorLink: an attempt at OSS sustainability
C#
31
star
13

xunit.assemblyfixture

Provides per-assembly fixture state support for xunit
C#
24
star
14

WebSocketPipe

System.IO.Pipelines API adapter for System.Net.WebSockets
C#
24
star
15

Merq

Internal application architecture via command and event messages
C#
23
star
16

TableStorage

Repository pattern with POCO object support for storing to Azure / Cosmos DB Table Storage
C#
21
star
17

Injector

Allows injecting .NET code into another Windows process
C++
12
star
18

WebSocketeer

High-performance intuitive API for Azure Web PubSub protobuf subprotocol
C#
11
star
19

xunit.vsix

Xunit for creating VSIX integration tests
C#
10
star
20

dotnet-tor

A .NET cross-platform CLI app that uses TorSharp to run a local proxy
C#
10
star
21

oss

Basic repo configuration for my OSS projects
SCSS
10
star
22

azdo

Home for azdo.io and accompanying linkinator source
C#
9
star
23

Dynamically

Instantiate record types from dynamic data with compatible structural shapes, in-memory with no reflection or serialization, via compile-time source generators.
C#
9
star
24

Web

XLinq to Web
HTML
8
star
25

chromium

Run a portable Chromium using dotnet 6+ and nuget.
C#
8
star
26

WebSocketChannel

High-performance System.Threading.Channels API adapter for System.Net.WebSockets
C#
8
star
27

dotnet-evergreen

A dotnet tool runner that automatically updates the tool package before and while running it
C#
6
star
28

CredentialManager

Packages the Git Credential Manager cross-platform implementation for Windows, macOS and Linux for use as a generic credential manager.
C#
6
star
29

dotnet-gcm

A dotnet global tool to interface with the Git Credentials Manager Core
C#
5
star
30

dotnet-eventgrid

Azure Function app and accompanying dotnet global tool to monitor Azure EventGrid streams in real-time.
C#
5
star
31

System.Diagnostics.Tracer

An improved API on top of System.Diagnostics
C#
5
star
32

json

JsonPeek and JsonPoke tasks implementations
C#
5
star
33

dotnet-stop

Gracefully stops processes by sending them SIGINT (Ctrl+C) in a cross platform way.
C#
4
star
34

nosayudamos.org

C#
3
star
35

catbag

A repository of loose helpers, base clases and assorted code
C#
3
star
36

scraper

A web scraping app that runs on Azure Container Apps
C#
3
star
37

actions-bot

A GitHub Action that sets bot secrets as git defaults if present
3
star
38

tsh

C#
2
star
39

cloudy

Spike on cloud-first architecture for apps, heavily event-driven
C#
2
star
40

PackageReferenceCleaner

Clean your PackageReferences with PrivateAssets=all into beautiful one-liners, automatically
C#
2
star
41

shields

Custom endpoints for custom badges using https://shields.io/endpoint
C#
2
star
42

Cognitive

Unified Cognitive API for Azure, Amazon and Google
C#
2
star
43

html

Loads Html documents as XLinq XDocuments
HTML
2
star
44

epub

A lightweight library that implements EPUB standard
C#
2
star
45

sponsors

Automatically updated list of devlooped sponsors
1
star
46

yaml

YamlPeek MSBuild Task
C#
1
star
47

actions-includes

Processes include HTML comments in files and inserts the included files
PowerShell
1
star
48

jq

A nuget distribution of the official JQ implementation, for easy consumption from .NET
C#
1
star
49

Azure.Functions.OpenApi

A zero-code OpenAPI (Swagger) basic generator for Azure Functions
C#
1
star
50

Mvp.Xml

C#
1
star
51

StreamR

An opinionated streaming-based library for running assistants with support for tool/function invocation and assistant behavior composition.
C#
1
star