问题描述
在将具有两个项目(Web应用程序和类库)的VS2015 MVC Core应用程序迁移到VS2017之后,我对类库中的所有视图都失去了智能感知.每个视图中的几乎所有内容都已损坏,因此我敢肯定,迁移工具没有为我提供帮助是相当基本的事情.甚至每个剃刀视图中的@model
指令都是错误.
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.
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.config
从Web应用程序复制到类库的根目录,但这无济于事.
I tried duplicating the web.config
from the web application to the root of the class library but that didn't help.
推荐答案
要解决此问题,需要做两件事:更改项目SDK(<Project Sdk="Microsoft.NET.Sdk.Web">
)并添加一个元素以将输出类型设置为库( <OutputType>Library</OutputType>
).我交叉张贴了有关 GitHub问题的完整信息.
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>
这篇关于.NET Core MVC自动迁移后,类库在VS2017中丢失了智能感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!