.NET Core MVC自动迁移后,类库在VS2017中丢失了智能感知

时间:2017-03-15 08:46:06

标签: asp.net-core asp.net-core-mvc intellisense class-library visual-studio-2017

将具有两个项目(Web应用程序和类库)的VS2015 MVC Core应用程序迁移到VS2017后,我在类库中的所有视图上都丢失了智能感知。几乎每个视图中的所有内容都被破坏了,所以我确信它是一个相当基本的东西,迁移工具没有为我照顾。甚至每个剃刀视图中的return ReactPropTypes.bool(props, propName, componentName, ...rest) || checker();指令都是错误的。

@model看起来像这样:

csproj

我尝试将<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> <AssemblyName>Library</AssemblyName> <PackageId>Library</PackageId> <PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback> <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> </PropertyGroup> <ItemGroup> <EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.1.0" /> </ItemGroup> </Project> 从Web应用程序复制到类库的根目录,但这没有帮助。

3 个答案:

答案 0 :(得分:1)

看起来你已经遇到了这个错误:

https://github.com/aspnet/Mvc/issues/5975

下面的旧答案

使用VS 2017的RTM版本,您需要安装Razor Language Service extension才能恢复Razor intellisense。

不幸的是,这个组件错过了内部发货日期,因此没有将其作为实际VS 2017版本的一部分。

答案 1 :(得分:1)

转到&#34;工具&#34>卸载Razor语言服务。 &GT; &#34;扩展和更新&#34;。

按照指示重新启动Visual Studio ......

重新安装Razor语言服务。

你会看到razor intellisense再次工作,比如asp- * tag helpers ......

答案 2 :(得分:0)

需要做两件事来解决这个问题,更改项目SDK(<Project Sdk="Microsoft.NET.Sdk.Web">)并添加一个元素来将输出类型设置为库(<OutputType>Library</OutputType>)。关于此GitHub issue的完整信息,我交叉发布。

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <OutputType>Library</OutputType>
    <AssemblyName>Library</AssemblyName>
    <PackageId>Library</PackageId>
    <PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
    <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
    <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
  </PropertyGroup>

  <ItemGroup>
    <EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.1.0" />
  </ItemGroup>

</Project>