雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

.Net报错Could not find a part of the path bin\roslyn\csc.exe

2024-10-14 16

维护一个老网站,用vs2022打开后build能成功,但是在IIS里运行的时候会报错:

Server Error in '/' Application.
Could not find a part of the path '...\bin\roslyn\csc.exe'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\bin\roslyn\csc.exe'.

在build的时候尝试找到\bin\roslyn\csc.exe,因为项目添加了

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Microsoft.Net.Compilers

这两个包,可以在packages.config里找到他们。

什么是Roslyn?谁在项目中添加了它们?

如果您使用 .net Framework 4.5.2 使用 VS2015 创建项目,您可能已经注意到项目模板默认使用 Roslyn。 实际上,Roslyn 是 Microsoft 的 .NET 语言的开源编译器之一。

如果你的项目有 Roslyn 引用并且您有兴趣将其部署在服务器上,你会在网站上收到不必要的错误,因为许多托管服务提供商仍未升级其服务器,因此不支持 Roslyn。 要解决此问题,需要从项目模板中删除 Roslyn 编译器。

所以我们不需要使用Roslyn,我们就可以删除它们。

在Package Manager Console里执行命令删除package:

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

PM> Uninstall-package Microsoft.Net.Compilers

对于我的项目我只添加过第一个个包所以只需要执行第一条就可以了。删除包后网站可以正常运行了。

更新于:4天前
赞一波!

文章评论

评论问答