Skip to content

Commit c879f25

Browse files
committed
Remove dependency on ThisAssembly
Simplifying the approach to leverage just SDK features makes it easier to consume and apply across projects that might not use ThisAssembly (or have version incompatibilities).
1 parent c4830fc commit c879f25

13 files changed

Lines changed: 261 additions & 76 deletions

src/SponsorLink/Analyzer/Analyzer.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
<None Update="buildTransitive\SponsorableLib.targets" Pack="true" />
3030
</ItemGroup>
3131

32+
<ItemGroup>
33+
<Compile Remove="C:\Code\devlooped.oss\src\SponsorLink\SponsorLink\ThisAssembly.cs" />
34+
</ItemGroup>
35+
3236
</Project>

src/SponsorLink/Analyzer/StatusReportingAnalyzer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.CodeAnalysis;
44
using Microsoft.CodeAnalysis.Diagnostics;
55
using static Devlooped.Sponsors.SponsorLink;
6-
using static ThisAssembly.Constants;
76

87
namespace Analyzer;
98

src/SponsorLink/SponsorLink.targets

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<MergeAnalyzerAssemblies Condition="'$(MergeAnalyzerAssemblies)' == '' and '$(Configuration)' == 'Release'">true</MergeAnalyzerAssemblies>
1010
<!-- If we are going to merge files, we need to copy local -->
1111
<CopyLocalLockFileAssemblies Condition="'$(MergeAnalyzerAssemblies)' == 'true'">true</CopyLocalLockFileAssemblies>
12+
<!-- Make Resources visible to intellisense -->
13+
<CoreCompileDependsOn>CoreResGen;$(CoreCompileDependsOn)</CoreCompileDependsOn>
1214

1315
<!-- Default funding product the Product, which already part of ThisAssembly -->
1416
<FundingProduct Condition="'$(FundingProduct)' == ''">$(Product)</FundingProduct>
@@ -18,20 +20,19 @@
1820
<FundingGrace Condition="'$(FundingGrace)' == ''">21</FundingGrace>
1921
</PropertyGroup>
2022

21-
<ItemGroup>
22-
<Constant Include="Funding.Product" Value="$(FundingProduct)" />
23-
<Constant Include="Funding.Prefix" Value="$(FundingPrefix)" />
24-
<Constant Include="Funding.Grace" Value="$(FundingGrace)" />
25-
</ItemGroup>
26-
2723
<ItemGroup>
2824
<Compile Include="$(MSBuildThisFileDirectory)SponsorLink/*.cs"
2925
Exclude="$(MSBuildThisFileDirectory)SponsorLink/bin/**;$(MSBuildThisFileDirectory)SponsorLink/obj/**"
3026
Source="SponsorLink"/>
3127
<EmbeddedResource Include="$(MSBuildThisFileDirectory)SponsorLink/*.resx"
3228
Exclude="$(MSBuildThisFileDirectory)SponsorLink/bin/**;$(MSBuildThisFileDirectory)SponsorLink/obj/**"
3329
Source="SponsorLink"
34-
ManifestResourceName="Devlooped.%(Filename)"/>
30+
ManifestResourceName="Devlooped.Sponsors.%(Filename)"/>
31+
<EmbeddedResource Update="$(MSBuildThisFileDirectory)SponsorLink/Resources.resx"
32+
StronglyTypedManifestPrefix="Devlooped.Sponsors"
33+
StronglyTypedClassName="%(Filename)"
34+
StronglyTypedNamespace="Devlooped.Sponsors"
35+
StronglyTypedLanguage="$(Language)" />
3536
<None Include="$(MSBuildThisFileDirectory)SponsorLink/buildTransitive/*.*"
3637
Source="SponsorLink"
3738
PackagePath="buildTransitive/%(Filename)%(Extension)"/>
@@ -81,6 +82,27 @@
8182
<PackageReference Include="ILRepack" Version="2.0.33" PrivateAssets="all" Pack="false" />
8283
</ItemGroup>
8384

85+
<Target Name="EmitFunding" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)SponsorLink.g.cs">
86+
<PropertyGroup>
87+
<SponsorLinkPartial>namespace Devlooped.Sponsors%3B
88+
89+
partial class SponsorLink
90+
{
91+
public partial class Funding
92+
{
93+
public const string Product = "$(FundingProduct)"%3B
94+
public const string Prefix = "$(FundingPrefix)"%3B
95+
public const int Grace = $(FundingGrace)%3B
96+
}
97+
}
98+
</SponsorLinkPartial>
99+
</PropertyGroup>
100+
<WriteLinesToFile File="$(IntermediateOutputPath)SponsorLink.g.cs" Lines="$(SponsorLinkPartial)" WriteOnlyWhenDifferent="true" Overwrite="true" />
101+
<ItemGroup>
102+
<Compile Include="$(IntermediateOutputPath)SponsorLink.g.cs" />
103+
</ItemGroup>
104+
</Target>
105+
84106
<Target Name="ILRepack" AfterTargets="CoreCompile" BeforeTargets="CopyFilesToOutputDirectory"
85107
Inputs="@(IntermediateAssembly -&gt; '%(FullPath)')"
86108
Outputs="$(IntermediateOutputPath)ilrepack.txt"

src/SponsorLink/SponsorLink/DiagnosticsManager.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#nullable enable
33
using System;
44
using System.Collections.Concurrent;
5+
using System.Globalization;
56
using Humanizer;
67
using Microsoft.CodeAnalysis;
78

@@ -92,47 +93,47 @@ public Diagnostic Push(string product, Diagnostic diagnostic)
9293

9394
static DiagnosticDescriptor CreateSponsor(string[] sponsorable, string prefix) => new(
9495
$"{prefix}100",
95-
ThisAssembly.Strings.Sponsor.Title,
96-
ThisAssembly.Strings.Sponsor.MessageFormat,
96+
Resources.Sponsor_Title,
97+
Resources.Sponsor_Message,
9798
"SponsorLink",
9899
DiagnosticSeverity.Info,
99100
isEnabledByDefault: true,
100-
description: ThisAssembly.Strings.Sponsor.Description,
101+
description: Resources.Sponsor_Description,
101102
helpLinkUri: "https://github.com/devlooped#sponsorlink",
102103
"DoesNotSupportF1Help");
103104

104105
static DiagnosticDescriptor CreateUnknown(string[] sponsorable, string product, string prefix) => new(
105106
$"{prefix}101",
106-
ThisAssembly.Strings.Unknown.Title,
107-
ThisAssembly.Strings.Unknown.MessageFormat,
107+
Resources.Unknown_Title,
108+
Resources.Unknown_Message,
108109
"SponsorLink",
109110
DiagnosticSeverity.Warning,
110111
isEnabledByDefault: true,
111-
description: ThisAssembly.Strings.Unknown.Description(
112+
description: string.Format(CultureInfo.CurrentCulture, Resources.Unknown_Description,
112113
sponsorable.Humanize(x => $"https://github.com/sponsors/{x}"),
113114
string.Join(" ", sponsorable)),
114115
helpLinkUri: "https://github.com/devlooped#sponsorlink",
115116
WellKnownDiagnosticTags.NotConfigurable);
116117

117118
static DiagnosticDescriptor CreateExpiring(string[] sponsorable, string prefix) => new(
118119
$"{prefix}103",
119-
ThisAssembly.Strings.Expiring.Title,
120-
ThisAssembly.Strings.Expiring.MessageFormat,
120+
Resources.Expiring_Title,
121+
Resources.Expiring_Message,
121122
"SponsorLink",
122123
DiagnosticSeverity.Warning,
123124
isEnabledByDefault: true,
124-
description: ThisAssembly.Strings.Expiring.Description(string.Join(" ", sponsorable)),
125+
description: string.Format(CultureInfo.CurrentCulture, Resources.Expiring_Description, string.Join(" ", sponsorable)),
125126
helpLinkUri: "https://github.com/devlooped#autosync",
126127
"DoesNotSupportF1Help", WellKnownDiagnosticTags.NotConfigurable);
127128

128129
static DiagnosticDescriptor CreateExpired(string[] sponsorable, string prefix) => new(
129130
$"{prefix}104",
130-
ThisAssembly.Strings.Expired.Title,
131-
ThisAssembly.Strings.Expired.MessageFormat,
131+
Resources.Expired_Title,
132+
Resources.Expired_Message,
132133
"SponsorLink",
133134
DiagnosticSeverity.Warning,
134135
isEnabledByDefault: true,
135-
description: ThisAssembly.Strings.Expired.Description(string.Join(" ", sponsorable)),
136+
description: string.Format(CultureInfo.CurrentCulture, Resources.Expired_Description, string.Join(" ", sponsorable)),
136137
helpLinkUri: "https://github.com/devlooped#autosync",
137138
"DoesNotSupportF1Help", WellKnownDiagnosticTags.NotConfigurable);
138139
}

src/SponsorLink/SponsorLink/SponsorLink.es.resx renamed to src/SponsorLink/SponsorLink/Resources.es.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
</resheader>
120120
<data name="Unknown_Description" xml:space="preserve">
121121
<value>Patrocinar los proyectos en que dependes asegura que se mantengan activos, y que recibas el apoyo que necesitas. También es muy económico y está disponible en todo el mundo!
122-
Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando posteriormente 'sponsor sync {spaced}'.</value>
122+
Por favor considera apoyar el proyecto patrocinando en {0} y ejecutando posteriormente 'sponsor sync {1}'.</value>
123123
</data>
124124
<data name="Unknown_Message" xml:space="preserve">
125125
<value>Por favor considere apoyar {0} patrocinando @{1} 🙏</value>
@@ -128,7 +128,7 @@ Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando post
128128
<value>Estado de patrocinio desconocido</value>
129129
</data>
130130
<data name="Expired_Description" xml:space="preserve">
131-
<value>Funcionalidades exclusivas para patrocinadores pueden no estar disponibles. Ejecuta 'sponsor sync {spaced}' y, opcionalmente, habilita la sincronización automática.</value>
131+
<value>Funcionalidades exclusivas para patrocinadores pueden no estar disponibles. Ejecuta 'sponsor sync {0}' y, opcionalmente, habilita la sincronización automática.</value>
132132
</data>
133133
<data name="Expired_Message" xml:space="preserve">
134134
<value>El estado de patrocino ha expirado y la sincronización automática no está habilitada.</value>
@@ -146,7 +146,7 @@ Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando post
146146
<value>Eres un patrocinador del proyecto, eres lo máximo 💟!</value>
147147
</data>
148148
<data name="Expiring_Description" xml:space="preserve">
149-
<value>El estado de patrocino ha expirado y estás en un período de gracia. Ejecuta 'sponsor sync {spaced}' y, opcionalmente, habilita la sincronización automática.</value>
149+
<value>El estado de patrocino ha expirado y estás en un período de gracia. Ejecuta 'sponsor sync {0}' y, opcionalmente, habilita la sincronización automática.</value>
150150
</data>
151151
<data name="Expiring_Message" xml:space="preserve">
152152
<value>El estado de patrocino necesita actualización periódica y la sincronización automática no está habilitada.</value>

src/SponsorLink/SponsorLink/SponsorLink.resx renamed to src/SponsorLink/SponsorLink/Resources.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
</resheader>
120120
<data name="Unknown_Description" xml:space="preserve">
121121
<value>Sponsoring projects you depend on ensures they remain active, and that you get the support you need. It's also super affordable and available worldwide!
122-
Please consider supporting the project by sponsoring at {links} and running 'sponsor sync {spaced}' afterwards.</value>
122+
Please consider supporting the project by sponsoring at {0} and running 'sponsor sync {1}' afterwards.</value>
123123
<comment>Unknown sponsor description</comment>
124124
</data>
125125
<data name="Unknown_Message" xml:space="preserve">
@@ -129,7 +129,7 @@ Please consider supporting the project by sponsoring at {links} and running 'spo
129129
<value>Unknown sponsor status</value>
130130
</data>
131131
<data name="Expired_Description" xml:space="preserve">
132-
<value>Sponsor-only features may be disabled. Please run 'sponsor sync {spaced}' and optionally enable automatic sync.</value>
132+
<value>Sponsor-only features may be disabled. Please run 'sponsor sync {0}' and optionally enable automatic sync.</value>
133133
</data>
134134
<data name="Expired_Message" xml:space="preserve">
135135
<value>Sponsor status has expired and automatic sync has not been enabled.</value>
@@ -147,7 +147,7 @@ Please consider supporting the project by sponsoring at {links} and running 'spo
147147
<value>You are a sponsor of the project, you rock 💟!</value>
148148
</data>
149149
<data name="Expiring_Description" xml:space="preserve">
150-
<value>Sponsor status has expired and you are in the grace period. Please run 'sponsor sync {spaced}' and optionally enable automatic sync.</value>
150+
<value>Sponsor status has expired and you are in the grace period. Please run 'sponsor sync {0}' and optionally enable automatic sync.</value>
151151
</data>
152152
<data name="Expiring_Message" xml:space="preserve">
153153
<value>Sponsor status needs periodic updating and automatic sync has not been enabled.</value>

src/SponsorLink/SponsorLink/SponsorLink.csproj

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<Product>SponsorLink</Product>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<GenerateDocumentationFile>false</GenerateDocumentationFile>
8+
<CoreCompileDependsOn>CoreResGen;$(CoreCompileDependsOn)</CoreCompileDependsOn>
89
</PropertyGroup>
910

1011
<PropertyGroup Label="SponsorLink">
@@ -24,30 +25,41 @@
2425
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
2526
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
2627
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" PrivateAssets="all" />
27-
<PackageReference Include="ThisAssembly.Constants" Version="1.4.3" PrivateAssets="all" />
28-
<PackageReference Include="ThisAssembly.Git" Version="1.4.3" PrivateAssets="all" />
29-
<PackageReference Include="ThisAssembly.Strings" Version="1.4.3" PrivateAssets="all" />
30-
<PackageReference Include="ThisAssembly.Project" Version="1.4.3" PrivateAssets="all" />
3128
</ItemGroup>
3229

3330
<ItemGroup>
34-
<EmbeddedResource Update="SponsorLink.es.resx" ManifestResourceName="Devlooped.%(Filename)" />
35-
<EmbeddedResource Update="SponsorLink.resx" ManifestResourceName="Devlooped.%(Filename)" />
36-
</ItemGroup>
37-
38-
<ItemGroup>
39-
<Constant Include="Funding.Product" Value="$(FundingProduct)" />
40-
<Constant Include="Funding.Prefix" Value="$(FundingPrefix)" />
41-
<Constant Include="Funding.Grace" Value="$(FundingGrace)" />
31+
<EmbeddedResource Update="Resources.es.resx" ManifestResourceName="Devlooped.Sponsors.%(Filename)"/>
32+
<EmbeddedResource Update="Resources.resx" ManifestResourceName="Devlooped.Sponsors.%(Filename)" StronglyTypedManifestPrefix="Devlooped.Sponsors" StronglyTypedClassName="%(Filename)" StronglyTypedNamespace="Devlooped.Sponsors" StronglyTypedLanguage="$(Language)" />
4233
</ItemGroup>
4334

4435
<ItemGroup>
4536
<None Include="..\SponsorLink.targets" Link="SponsorLink.targets" />
4637
</ItemGroup>
4738

39+
<Target Name="EmitFunding" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)SponsorLink.g.cs">
40+
<PropertyGroup>
41+
<SponsorLinkPartial>namespace Devlooped.Sponsors%3B
42+
43+
partial class SponsorLink
44+
{
45+
public partial class Funding
46+
{
47+
public const string Product = "$(FundingProduct)"%3B
48+
public const string Prefix = "$(FundingPrefix)"%3B
49+
public const int Grace = $(FundingGrace)%3B
50+
}
51+
}
52+
</SponsorLinkPartial>
53+
</PropertyGroup>
54+
<WriteLinesToFile File="$(IntermediateOutputPath)SponsorLink.g.cs" Lines="$(SponsorLinkPartial)" WriteOnlyWhenDifferent="true" Overwrite="true" />
55+
<ItemGroup>
56+
<Compile Include="$(IntermediateOutputPath)SponsorLink.g.cs" />
57+
</ItemGroup>
58+
</Target>
59+
4860
<Target Name="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes" Inputs="$(MSBuildProjectFullPath)" Outputs="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk">
4961
<Exec Command="pwsh -nop -f $(MSBuildThisFileDirectory)..\jwk.ps1" ConsoleToMSBuild="true" EchoOff="true">
50-
<Output TaskParameter="ConsoleOutput" PropertyName="DevloopedJwk"/>
62+
<Output TaskParameter="ConsoleOutput" PropertyName="DevloopedJwk" />
5163
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
5264
</Exec>
5365
<Error Text="$(DevloopedJwk)" Condition="'$(MSBuildLastExitCode)' != '0'" />

src/SponsorLink/SponsorLink/SponsorLinkAnalyzer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
using System.IO;
88
using System.Linq;
99
using Humanizer;
10+
using Humanizer.Localisation;
1011
using Microsoft.CodeAnalysis;
1112
using Microsoft.CodeAnalysis.Diagnostics;
1213
using static Devlooped.Sponsors.SponsorLink;
13-
using static ThisAssembly.Constants;
1414

1515
namespace Devlooped.Sponsors;
1616

@@ -20,7 +20,6 @@ namespace Devlooped.Sponsors;
2020
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
2121
public class SponsorLinkAnalyzer : DiagnosticAnalyzer
2222
{
23-
static readonly int graceDays = int.Parse(Funding.Grace);
2423
static readonly Dictionary<SponsorStatus, DiagnosticDescriptor> descriptors = new()
2524
{
2625
// Requires:
@@ -76,7 +75,7 @@ public override void Initialize(AnalysisContext context)
7675
// We'll report it as unknown as a fallback for now.
7776
ctx.ReportDiagnostic(Diagnostic.Create(descriptors[SponsorStatus.Unknown], null,
7877
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Unknown)),
79-
Funding.Product, Sponsorables.Keys.Humanize(ThisAssembly.Strings.Or)));
78+
Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)));
8079
}
8180
});
8281
}
@@ -93,13 +92,13 @@ SponsorStatus SetStatus(ImmutableArray<AdditionalText> manifests)
9392
// report unknown, either unparsed manifest or one with no expiration (which we never emit).
9493
Diagnostics.Push(Funding.Product, Diagnostic.Create(descriptors[SponsorStatus.Unknown], null,
9594
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Unknown)),
96-
Funding.Product, Sponsorables.Keys.Humanize(ThisAssembly.Strings.Or)));
95+
Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)));
9796
return SponsorStatus.Unknown;
9897
}
9998
else if (exp < DateTime.Now)
10099
{
101100
// report expired or expiring soon if still within the configured days of grace period
102-
if (exp.AddDays(graceDays) < DateTime.Now)
101+
if (exp.AddDays(Funding.Grace) < DateTime.Now)
103102
{
104103
// report expiring soon
105104
Diagnostics.Push(Funding.Product, Diagnostic.Create(descriptors[SponsorStatus.Expiring], null,

src/SponsorLink/SponsorLink/ThisAssembly.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)