编译错误,cshtml 文件中没有智能感知

Compilation errors and no intellisense in cshtml file

我有一个 winforms 应用程序,我正在尝试向它添加一个 cshtml 视图。根据网络上的一些文章,我尝试按照以下方式启用 visual studio 和智能感知支持:

到目前为止没有任何效果,语法无法识别并且文件产生了很多编译错误,例如

我的 cshtml 代码:

@using Hobbysta.Store.Orders
@using RazorLight
@inherits TemplatePage<Order>

<html>
    Testowy template, @Model.General.id_order
</html>

我的 csproj 文件

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <nullable>enable</nullable>
    <WarningsAsErrors>CS8600;CS8602;CS8603</WarningsAsErrors>
    <Version>0.5.1</Version>
  </PropertyGroup>

  <PropertyGroup>
    <PreserveCompilationReferences>true</PreserveCompilationReferences>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <WarningLevel>5</WarningLevel>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="Store\Orders\Print\OrdersPrintPageTemplate.cshtml" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="Store\Orders\Print\OrdersPrintPageTemplate.cshtml">
      <Generator>RazorTemplatePreprocessor</Generator>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="GrEmit" Version="3.3.7" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.2.0" />
    <PackageReference Include="NLog" Version="4.7.6" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
    <PackageReference Include="RazorLight" Version="2.0.0-rc.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Hobbysta\Hobbysta.csproj" />
    <ProjectReference Include="..\Hobbysta.Data\Hobbysta.Data.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Compile Update="Properties\Resources.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="RuntimeImplementations\" />
  </ItemGroup>

</Project>

我通过将构建操作设置为 none 解决了编译错误,对于智能感知,我不得不重新启动 visual studio。