Error on published ASP.NET core site: Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client'

久未见 提交于 2020-07-06 11:31:08

问题


My webb app works fine when run from Visual Studio, but when I publish and try to load a page, I get:

InvalidOperationException: Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client' Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List assemblies)

I've been stuck on this for quite a while. I've attempted to apply the various workarounds in the thread https://github.com/dotnet/core-setup/issues/2981, but none of them have worked.

My csproj file is pasted below. I'm not sure what other information would be useful:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <UserSecretsId>aspnet-CrowdQuery2-8C668DB3-5C80-4D9E-851D-2434D0CDA7E9</UserSecretsId>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
  </PropertyGroup>

  <PropertyGroup>
    <RuntimeFrameworkVersion>2.1.2</RuntimeFrameworkVersion>    
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.6" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.3" PrivateAssets="All" />
  </ItemGroup>

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

</Project>

回答1:


I've been having the same issue using Microsoft Azure.

The solution in this case was to clean up the wwwroot folder in our web app using Kudu (Development Tools -> Advanced Options), because there were some old DLLs still left from before the upgrade to .NET Core 2.1, because .NET Core 1 publishes the DLLs to the wwwroot folder, whereas in 2.1, the DLLs are loaded from a global store.

After having completely emptied the wwwroot folder, and redeploying the app, the error was resolved and the app ran as expected.




回答2:


I had to

(1)

Edit .csproj and add

<PropertyGroup>
  <MvcRazorExcludeRefAssembliesFromPublish>False</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>

(2)

Change the publish "Target Runtime" to "win-x64" (it was previously x86). I don't know why this is required, because my project properties -> Platform target is "Any CPU".

(I have two other similar websites in the same solution, neither of those .csproj files require that line, and both are still publishing to x86).



来源:https://stackoverflow.com/questions/52023291/error-on-published-asp-net-core-site-cannot-find-compilation-library-location-f

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