Orchardcore: Compile error: The 'Microsoft.NET.Sdk.Razor' SDK is required on Themes and Modules for Razor files to be precompiled.

Created on 13 Jun 2019  路  9Comments  路  Source: OrchardCMS/OrchardCore

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.


Condition="'@(RazorGenerate)' != '' and '$(ResolvedRazorCompileToolset)' != 'RazorSdk'"
Text="The 'Microsoft.NET.Sdk.Razor' SDK is required on Themes and Modules for Razor files to be precompiled." />

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.

<Project Sdk="Microsoft.NET.Sdk.Razor">

And as @zl2fxy said you also need a direct package reference on Microsoft.AspNetCore.Mvc.

All 9 comments

<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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cbadger360 picture cbadger360  路  4Comments

webmedia1012 picture webmedia1012  路  4Comments

jardg picture jardg  路  3Comments

lzw5399 picture lzw5399  路  3Comments

khoshroomahdi picture khoshroomahdi  路  4Comments