.NetCore2.0引用DLL报System.InvalidOperationException: Can not find compilation library location for package 'XXX'
.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>
最新文章
- Bash之PS1配置
- iOS - UIViewController
- 写个简单的ANT脚本来编译项目
- redis-消息订阅
- 转:测试用书(出处:cnblog--liangshi)
- Servlet API中文版
- css3简单几步画一个乾坤图
- 【朝花夕拾】朝花夕拾-Robot Framework实战演练之开篇
- springmvc图片上传(兼容ie8以上,实时预览)
- Mybatis的resultType
- JAVA物联网九大核心热点技术
- Pycharm安装并配置jupyter notebook
- Android广播机制的基本使用
- Java8-1-新特性_Lambda表达式
- Python全栈之路----函数----局部变量
- CCPC-Wannafly Winter Camp Day3 Div1 - 石头剪刀布 - [带权并查集]
- 快速排序javascript实现
- Oracle Grid Infrastructure Installation Guide for Linux 以debug模式安装并记录日志
- 20145304 Exp8 Web基础
- 第九章:叹词(L&#39;interjection )
热门文章
- GitHub车牌检测识别项目调研
- IT编程相关内容汇总 - 进阶者系列 - 学习者系列文章
- vue 中安装并使用echart
- .NET周报【1月第1期 2023-01-06】
- 每个Java程序员都必须知道的四种负载均衡算法
- [WPF]限制程序单例运行
- 【深入浅出Seata原理及实战】「入门基础专题」带你透析认识Seata分布式事务服务的原理和流程(1)
- 洛谷 P1208混合牛奶 题解
- 浏览器刷新时候不删除信息,关闭后删除用户信息处理办法,浏览器监听刷新以及删除事件、cookie、session、sessionStorage、localStorage区别
- 使用Ajax跨域实现百度搜索功能