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

Hen*_*nke 11 .net c# visual-studio asp.net-web-api

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

找不到文件... bin\roslyn\csc.exe:

应用程序中的服务器错误“/”。

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


重现错误的代码:http : //henke.atwebpages.com/SrvrErr-reproduce.zipfile 1
(原文来自 https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced /calling-a-web-api-from-a-net-client/sample/server/ProductsApp )


1请将扩展名从 重命名zipfilezip

Hen*_*nke 35

正如您已经提到的,快速修复是使用包管理器 Tools> Nuget Package Manager>Package Manager Console来运行

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
Run Code Online (Sandbox Code Playgroud)

正如/sf/ask/2294622081/#34391473所指出的

数据包管理器控制台 - 如何打开

但是另一种解决方案(我认为它更强大)是删除项目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>
Run Code Online (Sandbox Code Playgroud)

简而言之,删除以type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.

(据推测,相同的修复程序适用于 Visual Basic 和 Csharp,但我还没有尝试过。)

Visual Studio 将负责其余的工作。没有了Server Error in '/' Application

在我在上面的 zip 文件中提供的示例代码中,您现在可以HTTP Error 403 在点击Ctrl+时获得F5

HTTP 错误 403.14 - 禁止

尝试http://localhost:64195在您的 Web 浏览器中替换为http://localhost:64195/api/products.
Web API 现在显示为它应有的样子:

包含产品的 Web API

作为挑衅,我什至尝试删除package我的 Visual Studio 解决方案的整个目录。
一旦我(重新)构建它,它就会自动且无声地重新创建。