.NET CORE 2.0 MVC项目引用类库出现:System.InvalidOperationException: Can not find compilation library location for package 'XXX'

临时解决如下(据说2.0.1会修复):
在Startup.cs文件中:
修改:
public void ConfigureServices(IServiceCollection services)
{
var mvcBuilder = services.AddMvc();
new MvcConfiguration().ConfigureMvc(mvcBuilder);
}
添加:
public class MvcConfiguration : IDesignTimeMvcBuilderConfiguration
{
private class DirectReferenceAssemblyResolver : ICompilationAssemblyResolver
{
public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string> assemblies)
{
if (!string.Equals(library.Type, "reference", StringComparison.OrdinalIgnoreCase))
{
return false;
}

var paths = new List<string>();

foreach (var assembly in library.Assemblies)
{
var path = Path.Combine(ApplicationEnvironment.ApplicationBasePath, assembly);

if (!File.Exists(path))
{
return false;
}

paths.Add(path);
}

assemblies.AddRange(paths);

return true;
}
}

public void ConfigureMvc(IMvcBuilder builder)
{
// .NET Core SDK v1 does not pick up reference assemblies so
// they have to be added for Razor manually. Resolved for
// SDK v2 by https://github.com/dotnet/sdk/pull/876 OR SO WE THOUGHT
/*builder.AddRazorOptions(razor =>
{
razor.AdditionalCompilationReferences.Add(
MetadataReference.CreateFromFile(
typeof(PdfHttpHandler).Assembly.Location));
});*/

// .NET Core SDK v2 does not resolve reference assemblies' paths
// at all, so we have to hack around with reflection
typeof(CompilationLibrary)
.GetTypeInfo()
.GetDeclaredField("<DefaultResolver>k__BackingField")
.SetValue(null, new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[]
{
new DirectReferenceAssemblyResolver(),
new AppBaseCompilationAssemblyResolver(),
new ReferenceAssemblyPathResolver(),
new PackageCompilationAssemblyResolver(),
}));
}
}

.csproj中配置(如果有,确定是true,没有则不用管):
<PreserveCompilationContext>true</PreserveCompilationContext>

最新文章

  1. Bash之PS1配置
  2. iOS - UIViewController
  3. 写个简单的ANT脚本来编译项目
  4. redis-消息订阅
  5. 转:测试用书(出处:cnblog--liangshi)
  6. Servlet API中文版
  7. css3简单几步画一个乾坤图
  8. 【朝花夕拾】朝花夕拾-Robot Framework实战演练之开篇
  9. springmvc图片上传(兼容ie8以上,实时预览)
  10. Mybatis的resultType
  11. JAVA物联网九大核心热点技术
  12. Pycharm安装并配置jupyter notebook
  13. Android广播机制的基本使用
  14. Java8-1-新特性_Lambda表达式
  15. Python全栈之路----函数----局部变量
  16. CCPC-Wannafly Winter Camp Day3 Div1 - 石头剪刀布 - [带权并查集]
  17. 快速排序javascript实现
  18. Oracle Grid Infrastructure Installation Guide for Linux 以debug模式安装并记录日志
  19. 20145304 Exp8 Web基础
  20. 第九章:叹词(L&#39;interjection )

热门文章

  1. GitHub车牌检测识别项目调研
  2. IT编程相关内容汇总 - 进阶者系列 - 学习者系列文章
  3. vue 中安装并使用echart
  4. .NET周报【1月第1期 2023-01-06】
  5. 每个Java程序员都必须知道的四种负载均衡算法
  6. [WPF]限制程序单例运行
  7. 【深入浅出Seata原理及实战】「入门基础专题」带你透析认识Seata分布式事务服务的原理和流程(1)
  8. 洛谷 P1208混合牛奶 题解
  9. 浏览器刷新时候不删除信息,关闭后删除用户信息处理办法,浏览器监听刷新以及删除事件、cookie、session、sessionStorage、localStorage区别
  10. 使用Ajax跨域实现百度搜索功能