“找不到文件... bin\roslyn\csc.exe”

在 Visual Studio 2017 中,当按Ctrl+F5运行我的 ASP.NET Framework Web API 服务器时,我得到:

Could not find file ... bin\roslyn\csc.exe:

https://img1.sycdn.imooc.com/65abc63d0001759106530544.jpg

在包管理器控制台中运行 Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r 并不是永久修复,因为当包文件丢失时服务器错误会再次出现。如何一劳永逸地消除此错误,以便在我重新打开、生成和运行 Visual Studio 解决方案时自动(静默)重新安装所需的包?


重现错误的代码: https://user.it.uu.se/~hesc0353/RoslynError-reproduct.zip
(最初来自 https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api /overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp


斯蒂芬大帝
浏览 32回答 1
1回答

萧十郎

正如您已经提到的,快速解决方法是使用包管理器 >>Tools来运行Nuget Package ManagerPackage Manager ConsoleUpdate-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r但另一种解决方案(我认为更可靠)是删除项目Web.config文件的属性。(Web.config与您的文件位于同一目录中.csproj。)Web.config在文本编辑器(或 Visual Studio 中)中打开文件。- 在标签中configuration | system.codedom | compilers | compiler language="c#;cs;csharp",完全删除该type属性。<?xml version="1.0" encoding="utf-8"?><configuration>  <!-- ... -->  <system.codedom>    <compilers>      <compiler language="c#;cs;csharp" extension=".cs"        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>    </compilers>  </system.codedom></configuration>简而言之,删除以 开头的行type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft。(据推测,相同的修复方法适用于 Visual Basic 和 Csharp,但我还没有尝试过。)Visual Studio 将处理剩下的事情。不再Server Error in '/' Application。在我在上面的 zip 文件中提供的示例代码中,HTTP Error 403 当您点击Ctrl+时,您将得到F5。尝试http://localhost:64195在您的网络浏览器中替换为http://localhost:64195/api/products.Web API 现在显示应有的样子:作为挑衅,我什至尝试删除packageVisual Studio 解决方案的整个目录。当我(重新)构建它时,它就会自动且默默地重新创建。
打开App,查看更多内容
随时随地看视频慕课网APP