Class library lost intellisense in VS2017 after .NET Core MVC auto-migration

社会主义新天地 提交于 2019-12-11 03:24:11

问题


After migrating a VS2015 MVC Core application with two projects (web app and class library) to VS2017 I've lost intellisense on all views within the class library. Pretty much everything in every single view is broken, so I'm sure it's something fairly basic that the migration tool didn't take care of for me. Even the @model directive in each razor view is an error.

The csproj looks like this:

<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>

I tried duplicating the web.config from the web application to the root of the class library but that didn't help.


回答1:


Looks like you've hit this bug:

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

Old Answer below


With the RTM version of VS 2017, you need to install the Razor Language Service extension to get back your Razor intellisense.

Unfortunately this component missed an internal ship date and as such did not make it as part of the actual VS 2017 release.




回答2:


Uninstall the Razor Language Services by going to "Tools" > "Extensions and Updates".

Restart Visual Studio as per indication...

Reinstall Razor Language Services.

You will see razor intellisense working again such as asp-* tag helpers...




回答3:


Two things were required to fix this issue, a change to the project SDK (<Project Sdk="Microsoft.NET.Sdk.Web">) and adding an element to set the output type to a library (<OutputType>Library</OutputType>). Full information on this GitHub issue I cross-posted.

<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>


来源:https://stackoverflow.com/questions/42804844/class-library-lost-intellisense-in-vs2017-after-net-core-mvc-auto-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!