Skip to content

Commit 43cce5a

Browse files
authored
Merge pull request #27 from beheshty/bugfix/cannot-use-for-a-reference-library
fix: change missing source file error to warning and improve context
2 parents 1335c24 + f150c0b commit 43cce5a

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.0] - 2025-09-26
9+
### Changed
10+
- The diagnostic for a missing source file has been changed from a build-halting error to a non-blocking warning. The generator now continues without generating code instead of failing the compilation.
11+
- The warning for a missing source file now includes the name of the calling assembly to provide better context in multi-project solutions.
12+
813
## [3.0.0] - 2025-08-19
914
### Breaking Change
1015
- **Generator configuration has been moved from `appsettings.json` to MSBuild properties in the `.csproj` file.** The `SetSharp` section within `appsettings.json` is no longer read. Users upgrading to this version **must** migrate their settings to their project file to continue configuring the generator.

src/SetSharp/AnalyzerReleases.Shipped.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Rule ID | Category | Severity | Notes
77
SSG001 | Error | Error | App settings parsing failed. Triggered when internal parsing logic throws or fails due to invalid structure or unsupported types.
88
SSG002 | Usage | Error | Missing reference to 'Microsoft.Extensions.Options.ConfigurationExtensions' required for generating IOptions extensions.
99
SSG003 | Usage | Error | Missing reference(s) to 'Microsoft.Extensions.Configuration.Abstractions' and/or 'System.Collections.Immutable' required for basic functionality.
10-
SSG004 | Configuration | Error | The source file specified via MSBuild property was not found as an 'AdditionalFile' in the project.
10+
SSG004 | Configuration | Warning | The source file specified via MSBuild property was not found as an 'AdditionalFile' in the project.

src/SetSharp/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ internal static class DiagnosticDescriptors
2828
DiagnosticSeverity.Error,
2929
true);
3030

31-
internal static readonly DiagnosticDescriptor SourceFileNotFoundError = new(
31+
internal static readonly DiagnosticDescriptor SourceFileNotFoundWarning = new(
3232
"SSG004",
3333
"Source File Not Found",
34-
"The specified source file '{0}' was not found. Ensure the file is included in your project as an 'AdditionalFiles' item in the .csproj.",
34+
"The specified source file '{0}' was not found for assembly '{1}'. Ensure the file is included in your project as an 'AdditionalFiles' item in the .csproj.",
3535
"Configuration",
36-
DiagnosticSeverity.Error,
36+
DiagnosticSeverity.Warning,
3737
true);
3838
}
3939
}

src/SetSharp/SetSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111

1212
<PackageId>SetSharp</PackageId>
13-
<Version>3.0.1</Version>
13+
<Version>3.1.0</Version>
1414
<PackageIcon>icon.png</PackageIcon>
1515
<Authors>Amirhossein Beheshti</Authors>
1616
<Description>Generates strongly typed settings classes from appsettings.json using Source Generators.</Description>

src/SetSharp/SetSharpSourceGenerator.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2828

2929
if (sourceFile is null)
3030
{
31-
var diagnostic = Diagnostic.Create(DiagnosticDescriptors.SourceFileNotFoundError, Location.None, settings.SourceFile);
31+
var diagnostic = Diagnostic.Create(DiagnosticDescriptors.SourceFileNotFoundWarning, Location.None, settings.SourceFile, "unknown");
3232
return new SourceGenerationModel(null, settings, diagnostic);
3333
}
3434

@@ -58,7 +58,17 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5858
{
5959
var (model, compilation) = source;
6060

61-
if (model.Diagnostic != null)
61+
if (model.Diagnostic?.Id == DiagnosticDescriptors.SourceFileNotFoundWarning.Id)
62+
{
63+
var warning = Diagnostic.Create(
64+
DiagnosticDescriptors.SourceFileNotFoundWarning,
65+
Location.None,
66+
model.SetSharpSettings.SourceFile,
67+
compilation.AssemblyName);
68+
69+
spc.ReportDiagnostic(warning);
70+
}
71+
else if (model.Diagnostic != null)
6272
{
6373
spc.ReportDiagnostic(model.Diagnostic);
6474
return;

0 commit comments

Comments
 (0)