I got this error message when compiling a theme project, the error comes from a recent build.
In the theme's csproj file, I have this included already:
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" />
The only solution I found is to comment the followings in the OrchardCore.Module.Targets.targets file, but the error will come back again with a new build.
Text="The 'Microsoft.NET.Sdk.Razor' SDK is required on Themes and Modules for Razor files to be precompiled." />
<Target Name="EnsureRazorSdk" BeforeTargets="BeforeBuild">
<Error
Condition="'@(RazorGenerate)' != '' and '$(ResolvedRazorCompileToolset)' != 'RazorSdk'"
Text="The 'Microsoft.NET.Sdk.Razor' SDK is required on Themes and Modules for Razor files to be precompiled." />
</Target>
you try to add it at your theme's csproj file;
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" />
</ItemGroup>
Those are included in csproj file already:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.0.0-beta3-71653" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.0.0-beta3-71653" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.0.0-beta3-71653" />
<PackageReference Include="OrchardCore.Templates" Version="1.0.0-beta3-71653" />
<PackageReference Include="OrchardCore.Theme.Targets" Version="1.0.0-beta3-71653" />
<PackageReference Include="OrchardCore.Users" Version="1.0.0-beta3-71653" />
</ItemGroup>
All above were added via NuGet.
You don't need a package reference on Microsoft.NET.Sdk.Razor. You need to specify it as the project sdk through the 1st line of your project file.
<Project Sdk="Microsoft.NET.Sdk.Razor">
And as @zl2fxy said you also need a direct package reference on Microsoft.AspNetCore.Mvc.
problem solved, thanks both! :)
You don't need a package reference on
Microsoft.NET.Sdk.Razor. You need to specify it as the project sdk through the 1st line of your project file.<Project Sdk="Microsoft.NET.Sdk.Razor">
@jtkech Is this still a valid solution? The above solution doesn't seem consistent with the themes in the RC2 source.
@daerogami
Yes we are still using the razor sdk for our themes, unless those that are only using liquid files, no razor files
Most helpful comment
You don't need a package reference on
Microsoft.NET.Sdk.Razor. You need to specify it as the project sdk through the 1st line of your project file.And as @zl2fxy said you also need a direct package reference on
Microsoft.AspNetCore.Mvc.