Skip to content

Commit

Permalink
Add warning when using RazorBlade in an ASP.NET project
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Apr 22, 2024
1 parent afd6234 commit 992f172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/RazorBlade.Analyzers/Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Razor.Language;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

Expand All @@ -15,6 +16,7 @@ public enum Id
ConditionalOnAsync = 3,
EmbeddedLibraryUnsupportedCSharpVersion = 4,
TagHelpersNotSupported = 5,
[UsedImplicitly] UsingWithRazorSdk = 6
}

private static DiagnosticDescriptor RoslynError(Id id, string title, string messageFormat)
Expand Down
5 changes: 5 additions & 0 deletions src/RazorBlade/RazorBlade.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Namespace" />
</ItemGroup>

<Target Name="RazorBladeBeforeCompile" BeforeTargets="BeforeCompile">
<Warning Condition="'$(UsingMicrosoftNETSdkRazor)' == 'true'" Code="RB0006"
Text="RazorBlade shouldn't be used in ASP.NET projects, as several Razor source generators would process the same .cshtml files by default. ASP.NET's generator is not compatible with the RazorBlade library." />
</Target>

<Target Name="RazorBladePrepareAnalyzerInput" BeforeTargets="GenerateMSBuildEditorConfigFileCore">
<PropertyGroup>
<RazorBladeEmbeddedLibrary Condition="'$(RazorBladeEmbeddedLibrary)' == '' and @(PackageReference->WithMetadataValue('Identity', 'RazorBlade')->AnyHaveMetadataValue('PrivateAssets', 'all'))">True</RazorBladeEmbeddedLibrary>
Expand Down

0 comments on commit 992f172

Please sign in to comment.